Skip to content

Commit

Permalink
Remove html formatting in a warn statement.
Browse files Browse the repository at this point in the history
Here is a minimal working example to demonstrate the change:
```perl
DOCUMENT();
loadMacros('PGstandard.pl');
BEGIN_TEXT
\{ foo() \}
END_TEXT
ENDDOCUMENT();
```

With the develop branch the warning messages for this problem will be:

* `ERROR in old_safe_ev, PGbasicmacros.pl: <PRE>`
* `## There is an error occuring inside evaluation brackets \{ ...code... \}`
* `## somewhere in an EV2 or EV3 or BEGIN_TEXT block.`
* `## Code evaluated:`
* `## foo()`
* `##Undefined subroutine &main::foo called at line 1 of (eval 7649).`
* `##</PRE><BR>`
* `at line 2080 of [PG]/macros/core/PGbasicmacros.pl.`

Since these warnings are now xml escaped by webwork2 the html formatting
no longer works.

With this branch they will be:

* `There is an error occuring inside evaluation brackets \{ ...code... \} somewhere in an EV2, EV3, or BEGIN_TEXT block.`
* `Code evaluated:`
* `foo()`
* `Errors:`
* `Undefined subroutine &main::foo called at line 1 of (eval 7742).`

I don't think that the "ERROR in old_safe_ev, PGbasicmacros.pl" part is
useful for problem authors, so that was dropped.

Also remove the `;` from the end of the eval, and the comment about it.
Testing shows that comment is false.
  • Loading branch information
drgrice1 committed Aug 22, 2023
1 parent 350657e commit 5413c17
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions macros/core/PGbasicmacros.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2072,23 +2072,18 @@ sub safe_ev {

sub old_safe_ev {
my $in = shift;
my ($out, $PG_eval_errors, $PG_full_error_report) = PG_restricted_eval("$in;");
# the addition of the ; seems to provide better error reporting
my ($out, $PG_eval_errors, $PG_full_error_report) = PG_restricted_eval($in);
if ($PG_eval_errors) {
my @errorLines = split("\n", $PG_eval_errors);
#$out = "<PRE>$PAR % ERROR in $0:old_safe_ev, PGbasicmacros.pl: $PAR % There is an error occuring inside evaluation brackets \\{ ...code... \\} $BR % somewhere in an EV2 or EV3 or BEGIN_TEXT block. $BR % Code evaluated:$BR $in $BR % $BR % $errorLines[0]\n % $errorLines[1]$BR % $BR % $BR </PRE> ";
warn " ERROR in old_safe_ev, PGbasicmacros.pl: <PRE>
## There is an error occuring inside evaluation brackets \\{ ...code... \\}
## somewhere in an EV2 or EV3 or BEGIN_TEXT block.
## Code evaluated:
## $in
##" . join("\n ", @errorLines) . "
##</PRE>$BR
";
warn "There is an error occuring inside evaluation brackets \\{ ...code... \\} "
. "somewhere in an EV2, EV3, or BEGIN_TEXT block.\n"
. "Code evaluated:\n$in\n"
. "Errors:\n"
. join("\n", @errorLines) . "\n";
$out = "$PAR $BBOLD $in $EBOLD $PAR";
}

($out, $PG_eval_errors, $PG_full_error_report);
return ($out, $PG_eval_errors, $PG_full_error_report);
}

sub FEQ { # Format EQuations
Expand Down

0 comments on commit 5413c17

Please sign in to comment.