Better template diagnostics on failure. It now also includes the template URL, and templateId
in both the onscreen and logged output.
This commit is contained in:
parent
4252b359dc
commit
8a683d1aef
9 changed files with 100 additions and 73 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
- fixed: getNextThread/getPreviousThread won't sort by thread rating
|
- fixed: getNextThread/getPreviousThread won't sort by thread rating
|
||||||
- fixed: #10485: User not returned to asset manager after adding content to /impor
|
- fixed: #10485: User not returned to asset manager after adding content to /impor
|
||||||
- fixed: #10262: Default Inbox View Template: Mismatch in HTML for upper and lower page navigation
|
- fixed: #10262: Default Inbox View Template: Mismatch in HTML for upper and lower page navigation
|
||||||
|
- fixed rfe #10474: Improve error message for template errors
|
||||||
|
|
||||||
7.7.9
|
7.7.9
|
||||||
- fixed #10266: Public Profile overrides Able to be friend
|
- fixed #10266: Public Profile overrides Able to be friend
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ use WebGUI::International;
|
||||||
use WebGUI::Asset::Template::HTMLTemplate;
|
use WebGUI::Asset::Template::HTMLTemplate;
|
||||||
use WebGUI::Utility;
|
use WebGUI::Utility;
|
||||||
use WebGUI::Form;
|
use WebGUI::Form;
|
||||||
|
use WebGUI::Exception;
|
||||||
use Tie::IxHash;
|
use Tie::IxHash;
|
||||||
use Clone qw/clone/;
|
use Clone qw/clone/;
|
||||||
use HTML::Packer;
|
use HTML::Packer;
|
||||||
|
|
@ -374,9 +375,9 @@ sub getEditForm {
|
||||||
);
|
);
|
||||||
|
|
||||||
my ($style, $url) = $self->session->quick(qw(style url));
|
my ($style, $url) = $self->session->quick(qw(style url));
|
||||||
$style->setScript($url->extras('yui/build/yahoo/yahoo-min.js'));
|
$style->setScript($url->extras('yui/build/yahoo/yahoo-min.js'), {type => 'text/javascript'});
|
||||||
$style->setScript($url->extras('yui/build/json/json-min.js'));
|
$style->setScript($url->extras('yui/build/json/json-min.js'), {type => 'text/javascript'});
|
||||||
$style->setScript($url->extras('yui/build/dom/dom-min.js'));
|
$style->setScript($url->extras('yui/build/dom/dom-min.js'), {type => 'text/javascript'});
|
||||||
|
|
||||||
pop(@headers);
|
pop(@headers);
|
||||||
my $scriptUrl = $url->extras('templateAttachments.js');
|
my $scriptUrl = $url->extras('templateAttachments.js');
|
||||||
|
|
@ -595,7 +596,14 @@ sub process {
|
||||||
? $self->get('templatePacked')
|
? $self->get('templatePacked')
|
||||||
: $self->get('template')
|
: $self->get('template')
|
||||||
;
|
;
|
||||||
return $parser->process($template, $vars);
|
my $output;
|
||||||
|
eval { $output = $parser->process($template, $vars); };
|
||||||
|
if (my $e = Exception::Class->caught) {
|
||||||
|
$self->session->log->error(sprintf "Error processing template: %s, %s, %s", $self->getUrl, $self->getId, $e->error);
|
||||||
|
my $i18n = WebGUI::International->new($self->session, 'Asset_Template');
|
||||||
|
$output = sprintf $i18n->get('template error').$e->error, $self->getUrl, $self->getId;
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ package WebGUI::Asset::Template::HTMLTemplate;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use base 'WebGUI::Asset::Template::Parser';
|
use base 'WebGUI::Asset::Template::Parser';
|
||||||
|
use WebGUI::Exception;
|
||||||
use HTML::Template;
|
use HTML::Template;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -50,28 +51,25 @@ A hash reference containing template variables and loops.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub process {
|
sub process {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $template = shift;
|
my $template = shift;
|
||||||
my $vars = $self->addSessionVars(shift);
|
my $vars = $self->addSessionVars(shift);
|
||||||
my $t;
|
my $t;
|
||||||
eval {
|
eval {
|
||||||
$t = HTML::Template->new(
|
$t = HTML::Template->new(
|
||||||
scalarref=>\$template,
|
scalarref=>\$template,
|
||||||
global_vars=>1,
|
global_vars=>1,
|
||||||
loop_context_vars=>1,
|
loop_context_vars=>1,
|
||||||
die_on_bad_params=>0,
|
die_on_bad_params=>0,
|
||||||
no_includes=>1,
|
no_includes=>1,
|
||||||
strict=>0
|
strict=>0
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
unless ($@) {
|
if ($@) {
|
||||||
$t->param(%{$vars});
|
WebGUI::Error::Template->throw( error => $@ );
|
||||||
return $t->output;
|
}
|
||||||
} else {
|
$t->param(%{$vars});
|
||||||
$self->session->errorHandler->error("Error in template. ".$@);
|
return $t->output;
|
||||||
return WebGUI::International->new($self->session, 'Asset_Template')->get('template error').$@;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ package WebGUI::Asset::Template::HTMLTemplateExpr;
|
||||||
use strict;
|
use strict;
|
||||||
use base 'WebGUI::Asset::Template::Parser';
|
use base 'WebGUI::Asset::Template::Parser';
|
||||||
use HTML::Template::Expr;
|
use HTML::Template::Expr;
|
||||||
|
use WebGUI::Exception;
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -77,25 +78,23 @@ A hash reference containing template variables and loops.
|
||||||
# about the template that has the error. Finding an "ERROR: Error in template"
|
# about the template that has the error. Finding an "ERROR: Error in template"
|
||||||
# in the error log is not very helpful...
|
# in the error log is not very helpful...
|
||||||
sub process {
|
sub process {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $template = shift;
|
my $template = shift;
|
||||||
my $vars = $class->addSessionVars(shift);
|
my $vars = $class->addSessionVars(shift);
|
||||||
my $t;
|
my $t;
|
||||||
eval {
|
eval {
|
||||||
$t = HTML::Template::Expr->new(scalarref=>\$template,
|
$t = HTML::Template::Expr->new(scalarref=>\$template,
|
||||||
global_vars=>1,
|
global_vars=>1,
|
||||||
loop_context_vars=>1,
|
loop_context_vars=>1,
|
||||||
die_on_bad_params=>0,
|
die_on_bad_params=>0,
|
||||||
no_includes=>1,
|
no_includes=>1,
|
||||||
strict=>0);
|
strict=>0);
|
||||||
};
|
};
|
||||||
unless ($@) {
|
if ($@) {
|
||||||
$t->param(%{_rewriteVars($vars)});
|
WebGUI::Error::Template->throw( error => $@ );
|
||||||
return $t->output;
|
}
|
||||||
} else {
|
$t->param(%{_rewriteVars($vars)});
|
||||||
$class->session->errorHandler->error("Error in template. ".$@);
|
return $t->output;
|
||||||
return WebGUI::International->new($class->session,'Asset_Template')->get('template error').$@;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -71,25 +71,22 @@ A hash reference containing template variables and loops.
|
||||||
# about the template that has the error. Finding an "ERROR: Error in template"
|
# about the template that has the error. Finding an "ERROR: Error in template"
|
||||||
# in the error log is not very helpful...
|
# in the error log is not very helpful...
|
||||||
sub process {
|
sub process {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $template = shift;
|
my $template = shift;
|
||||||
my $vars = $self->addSessionVars(shift);
|
my $vars = $self->addSessionVars(shift);
|
||||||
my ($t,$output);
|
my ($t,$output);
|
||||||
eval {
|
eval {
|
||||||
$t = Template->new( {
|
$t = Template->new({
|
||||||
INTERPOLATE => 1, # expand "$var" in plain text
|
INTERPOLATE => 1, # expand "$var" in plain text
|
||||||
POST_CHOMP => 1, # cleanup whitespace
|
POST_CHOMP => 1, # cleanup whitespace
|
||||||
EVAL_PERL => 0, # evaluate Perl code blocks
|
EVAL_PERL => 0, # evaluate Perl code blocks
|
||||||
});
|
});
|
||||||
$t->process( \$template, _rewriteVars($vars),\$output) || $self->session->errorHandler->error($t->error());
|
$t->process( \$template, _rewriteVars($vars),\$output) || $self->session->errorHandler->error($t->error());
|
||||||
};
|
};
|
||||||
unless($@){
|
if ($@) {
|
||||||
return $output;
|
WebGUI::Error::Template->throw( error => $@ );
|
||||||
} else {
|
}
|
||||||
$self->session->errorHandler->error("Error in template. ".$@);
|
return $output;
|
||||||
return WebGUI::International->new($self->session,'Asset_Template')->get('template error').$@;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ package WebGUI::Asset::Template::SomeTemplateType;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use base 'WebGUI::Asset::Template::Parser';
|
use base 'WebGUI::Asset::Template::Parser';
|
||||||
|
use WebGUI::Exception;
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -52,7 +53,12 @@ sub process {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $template = shift;
|
my $template = shift;
|
||||||
my $vars = $self->addSessionVars(shift);
|
my $vars = $self->addSessionVars(shift);
|
||||||
...
|
eval {
|
||||||
|
|
||||||
|
}
|
||||||
|
if ($@) {
|
||||||
|
WebGUI::Error::Template->throw( error => $@ );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,10 @@ use Exception::Class (
|
||||||
description => "The file you have provided has errors.",
|
description => "The file you have provided has errors.",
|
||||||
fields => [qw{ brokenFile brokenLine }],
|
fields => [qw{ brokenFile brokenLine }],
|
||||||
},
|
},
|
||||||
|
'WebGUI::Error::Template' => {
|
||||||
|
isa => 'WebGUI::Error',
|
||||||
|
description => "A template has errors that prevent it from being processed.",
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ our $I18N = {
|
||||||
},
|
},
|
||||||
|
|
||||||
'template error' => {
|
'template error' => {
|
||||||
message => q|There is a syntax error in this template. Please correct.|,
|
message => q|There is a syntax error in this template, %s, %s. Please correct.|,
|
||||||
context => q|Error when executing template|,
|
context => q|Error when executing template|,
|
||||||
lastUpdated => 1107391368,
|
lastUpdated => 1244476530,
|
||||||
},
|
},
|
||||||
|
|
||||||
'namespace description' => {
|
'namespace description' => {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ use lib "$FindBin::Bin/../lib";
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::Asset::Template;
|
use WebGUI::Asset::Template;
|
||||||
use Test::More tests => 32; # increment this value for each test you create
|
use Exception::Class;
|
||||||
|
use Test::More tests => 37; # increment this value for each test you create
|
||||||
use Test::Deep;
|
use Test::Deep;
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
@ -109,11 +110,24 @@ is(@$att4, 3, 'rev is proper size');
|
||||||
|
|
||||||
$template3rev->purgeRevision();
|
$template3rev->purgeRevision();
|
||||||
|
|
||||||
|
my $brokenTemplate = $importNode->addChild({
|
||||||
|
className => "WebGUI::Asset::Template",
|
||||||
|
title => 'Broken template',
|
||||||
|
template => q|<tmpl_if unclosedIf>If clause with no ending tag|,
|
||||||
|
});
|
||||||
|
|
||||||
# done checking revision stuff
|
# done checking revision stuff
|
||||||
|
|
||||||
$template->purge;
|
WebGUI::Test->interceptLogging;
|
||||||
$templateCopy->purge;
|
my $brokenOutput = $brokenTemplate->process({});
|
||||||
$template3->purge;
|
my $logError = $WebGUI::Test::logger_error;
|
||||||
WebGUI::VersionTag->getWorking($session)->rollback;
|
my $brokenUrl = $brokenTemplate->getUrl;
|
||||||
|
my $brokenId = $brokenTemplate->getId;
|
||||||
|
like($brokenOutput, qr/^There is a syntax error in this template/, 'process: returned error output contains boilerplate');
|
||||||
|
like($brokenOutput, qr/$brokenUrl/, '... and the template url');
|
||||||
|
like($brokenOutput, qr/$brokenId/, '... and the template id');
|
||||||
|
like($logError, qr/$brokenUrl/, 'process: logged error has the url');
|
||||||
|
like($logError, qr/$brokenId/, '... and the template id');
|
||||||
|
|
||||||
|
WebGUI::Test->tagsToRollback(WebGUI::VersionTag->getWorking($session));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue