Skip to content

Commit

Permalink
Trouble shoot warning message passing. Restore "edit problem" line when
Browse files Browse the repository at this point in the history
warnings occur.

Using the opportunity provided by having the level_curves subroutine
fail to make sure that the appropriate warning messages are passed and that
one  can get back to the PGeditor to make corrections.
  • Loading branch information
mgage committed Feb 27, 2012
1 parent 23dca36 commit 7fed2ad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
6 changes: 3 additions & 3 deletions lib/WeBWorK/ContentGenerator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ The implementation in this package checks for a note in the request named
sub warnings {
my ($self) = @_;
my $r = $self->r;

print CGI::p("Entering ContentGenerator::warnings");
print "\n<!-- BEGIN " . __PACKAGE__ . "::warnings -->\n";
my $warnings = MP2 ? $r->notes->get("warnings") : $r->notes("warnings");
print $self->warningOutput($warnings) if $warnings;
Expand Down Expand Up @@ -1949,7 +1949,7 @@ problem rendering.
sub errorOutput($$$) {
my ($self, $error, $details) = @_;
my $r = $self->{r};

print "Entering ContentGenerator::errorOutput subroutine</br>";
my $time = time2str("%a %b %d %H:%M:%S %Y", time);
my $method = $r->method;
my $uri = $r->uri;
Expand Down Expand Up @@ -2007,7 +2007,7 @@ and content generation.
sub warningOutput($$) {
my ($self, $warnings) = @_;
my $r = $self->{r};

print "Entering ContentGenerator::warningOutput subroutine</br>";
my @warnings = split m/\n+/, $warnings;
foreach my $warning (@warnings) {
#$warning = escapeHTML($warning); # this would prevent using tables in output from answer evaluators
Expand Down
48 changes: 30 additions & 18 deletions lib/WeBWorK/ContentGenerator/Problem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -726,12 +726,14 @@ sub pre_header_initialize {
# because the PG file is never run
#
if (defined ($pg->{pgcore}) ) {
my @debug_msgs = @{ $pg->{pgcore}->get_debug_messages};
$self->addmessage(join(CGI::br(),@debug_msgs) ) if @debug_msgs;
my $debug_msg = CGI::br().join( CGI::br(), @{ $pg->{pgcore}->get_debug_messages});
$self->addmessage($debug_msg ) if $debug_msg;
$self->{pgdebug} = $pg->{pgcore}->get_debug_messages;
$self->{pgwarning} = $pg->{pgcore}->get_warning_messages;
$self->{pginternalerrors} = $pg->{pgcore}->get_internal_debug_messages ;
$self->{pgerrors} = @{$self->{pgdebug}} || @{$self->{pgwarning}} || @{$self->{pginternalerrors}};
$self->{pgerrors} = @{$self->{pgdebug}} || @{$self->{pgwarning}} || @{$self->{pginternalerrors}}||0;
} else {
$self->{pgerrors}=undef; # unable to obtain errors
}

debug("end pg processing");
Expand All @@ -752,23 +754,30 @@ sub pre_header_initialize {
}
sub warnings {
my $self = shift;
$self->SUPER::warnings();
my $r = $self->r;
my $pg = $self->{pg};

my @pgdebug = @{ $self->{pgdebug} };
my @pgwarning = @{ $self->{pgwarning} };
my @pginternalerrors = @{ $self->{pginternalerrors} };
# my $pgerrordiv = $pgdebug||$pgwarning||$pginternalerrors; # is 1 if any of these are non-empty
# print "entering warnings() subroutine internal messages = ", $self->{pgerrors},CGI::br();
my $r = $self->r;
# my $pg = $self->{pg};
# warn "type of pg is ",ref($pg);
# my $pgerrordiv = $pgdebug||$pgwarning||$pginternalerrors; # is 1 if any of these are non-empty
# print warning messages
if ( $self->{pgerrors} ) {
if (not defined $self->{pgerrors} ) {
print CGI::start_div();
print CGI::h3({style=>"color:red;"}, $r->maketext("PG question failed to render"));
print CGI::p($r->maketext("Unable to obtain error messages from within the PG question." ));
print CGI::end_div();
} elsif ( $self->{pgerrors} > 0 ) {
my @pgdebug = @{ $self->{pgdebug} };
my @pgwarning = @{ $self->{pgwarning} };
my @pginternalerrors = @{ $self->{pginternalerrors} };
print CGI::start_div();
print CGI::h3({style=>"color:red;"}, $r->maketext("Additional Error Messages"));
print CGI::p(CGI::h3("PG debug messages"), CGI::br(), @pgdebug ) if @pgdebug ;
print CGI::p(CGI::h3("PG warning messages"), CGI::br(), @pgwarning ) if @pgwarning ;
print CGI::p(CGI::h3("PG internal errors"), CGI::br(), @pginternalerrors ) if @pginternalerrors;
print CGI::h3({style=>"color:red;"}, $r->maketext("PG question processing error messages"));
print CGI::p(CGI::h3($r->maketext("PG debug messages" ) ), CGI::br(), join(CGI::br(), @pgdebug ) ) if @pgdebug ;
print CGI::p(CGI::h3($r->maketext("PG warning messages" ) ), CGI::br(), join(CGI::br(), @pgwarning) ) if @pgwarning ;
print CGI::p(CGI::h3($r->maketext("PG internal errors" ) ), CGI::br(), join(CGI::br(), @pginternalerrors )) if @pginternalerrors;
print CGI::end_div();
}
}
# print "proceeding to SUPER::warnings";
$self->SUPER::warnings();
"";
}

Expand Down Expand Up @@ -924,7 +933,7 @@ sub body {
my $set = $self->{set};
my $problem = $self->{problem};
my $pg = $self->{pg};

print CGI::p("Entering Problem::body subroutine. This indicates an older style system.template file -- consider upgrading. ");
my $valid = WeBWorK::ContentGenerator::ProblemUtil::ProblemUtil::check_invalid($self);
unless($valid eq "valid"){
return $valid;
Expand Down Expand Up @@ -1048,10 +1057,13 @@ sub output_editorLink{

if ($pg->{flags}->{error_flag}) {
if ($authz->hasPermissions($user, "view_problem_debugging_info")) {
print "Call errorOutput</br>";
print $self->errorOutput($pg->{errors}, $pg->{body_text});
print $editorLink;
} else {
print $self->errorOutput($pg->{errors}, $r->maketext("You do not have permission to view the details of this error."));
}

print "";
}
else{
Expand Down

0 comments on commit 7fed2ad

Please sign in to comment.