From 7fed2ad82d2e9aec285ddb1fd496fdb0c1768b52 Mon Sep 17 00:00:00 2001 From: Michael Gage Date: Sun, 26 Feb 2012 21:02:13 -0500 Subject: [PATCH] Trouble shoot warning message passing. Restore "edit problem" line when 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. --- lib/WeBWorK/ContentGenerator.pm | 6 ++-- lib/WeBWorK/ContentGenerator/Problem.pm | 48 +++++++++++++++---------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/lib/WeBWorK/ContentGenerator.pm b/lib/WeBWorK/ContentGenerator.pm index 1d23ca45c1..d425e7c91b 100644 --- a/lib/WeBWorK/ContentGenerator.pm +++ b/lib/WeBWorK/ContentGenerator.pm @@ -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\n"; my $warnings = MP2 ? $r->notes->get("warnings") : $r->notes("warnings"); print $self->warningOutput($warnings) if $warnings; @@ -1949,7 +1949,7 @@ problem rendering. sub errorOutput($$$) { my ($self, $error, $details) = @_; my $r = $self->{r}; - + print "Entering ContentGenerator::errorOutput subroutine
"; my $time = time2str("%a %b %d %H:%M:%S %Y", time); my $method = $r->method; my $uri = $r->uri; @@ -2007,7 +2007,7 @@ and content generation. sub warningOutput($$) { my ($self, $warnings) = @_; my $r = $self->{r}; - + print "Entering ContentGenerator::warningOutput subroutine
"; my @warnings = split m/\n+/, $warnings; foreach my $warning (@warnings) { #$warning = escapeHTML($warning); # this would prevent using tables in output from answer evaluators diff --git a/lib/WeBWorK/ContentGenerator/Problem.pm b/lib/WeBWorK/ContentGenerator/Problem.pm index a82756f04e..ec8046e579 100644 --- a/lib/WeBWorK/ContentGenerator/Problem.pm +++ b/lib/WeBWorK/ContentGenerator/Problem.pm @@ -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"); @@ -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(); ""; } @@ -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; @@ -1048,10 +1057,13 @@ sub output_editorLink{ if ($pg->{flags}->{error_flag}) { if ($authz->hasPermissions($user, "view_problem_debugging_info")) { + print "Call errorOutput
"; 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{