/[pub]/suikawiki/script/lib/SuikaWiki/Plugin/Error.wp2
Suika

Contents of /suikawiki/script/lib/SuikaWiki/Plugin/Error.wp2

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations) (download)
Wed Feb 18 07:18:30 2004 UTC (22 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.6: +25 -3 lines
WikiDB Error reporting bug fixed

1 wakaba 1.1 #?SuikaWikiConfig/2.0
2    
3     Plugin:
4     @Name: Error
5     @Description:
6     @@@: Error handling core module
7     @@lang:en
8 wakaba 1.6 @License: %%Perl%%
9 wakaba 1.1 @Author:
10     @@Name:
11     @@@@: Wakaba
12     @@@lang:ja
13     @@@script:Latn
14     @@Mail[list]: [email protected]
15 wakaba 1.6 @Date.RCS:
16 wakaba 1.7 $Date: 2004/02/14 10:58:14 $
17 wakaba 1.1 @RequiredPlugin[list]:
18     WikiView
19     WikiStruct
20     HTML
21     WikiResource
22     @Use:
23 wakaba 1.4 my $WIKIRESOURCE;
24 wakaba 1.1
25     PluginConst:
26     @NS_XHTML1:
27     http://www.w3.org/1999/xhtml
28 wakaba 1.4 @WIKIRESOURCE:
29     {($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))}
30 wakaba 1.1
31     ViewDefinition:
32     @Mode: -error
33     @Condition:
34     @@http-method[list]:
35     GET
36     HEAD
37     @Description:
38 wakaba 1.3 @@@: Fatal error reporting special "view"
39     @@lang: en
40     @template:
41     @@http-status-code: 500
42     @@http-status-phrase: Internal WikiEngine Error
43     @@media-type: text/html
44     @@use-media-type-charset: 1
45     @@expires: %%error%%
46     @@body:
47     %html-document (
48     title => {%res (name => {Error:WebPageTitle});}p,
49     link-meta => {%template (name => links);}p,
50     content => {
51 wakaba 1.5 %section (
52 wakaba 1.3 title => {%res (name => {Error:Title});}p, heading,
53     content => {%paragraph (
54     content => {%res (name => {Error:Description});}p,
55     );%error-list (
56 wakaba 1.6 id => err--error,
57 wakaba 1.3 no-error => {%res (name => {Error:NoErrorReported});}p,
58     );}p,
59     );
60 wakaba 1.5 %block (id => footer, content => {%template (name => ws--footer);}p);
61 wakaba 1.3 }p,
62     );
63    
64     ViewDefinition:
65     @Mode: -general-error
66     @Condition:
67     @@http-method[list]:
68     GET
69     HEAD
70     @Description:
71 wakaba 1.1 @@@: Error reporting special "view"
72     @@lang: en
73     @template:
74     @@http-status-code: 500
75     @@http-status-phrase: Internal WikiEngine Error
76     @@media-type: text/html
77     @@use-media-type-charset: 1
78     @@expires: %%error%%
79     @@body:
80     %html-document (
81     title => {%res (name => {Error:WebPageTitle});}p,
82     link-meta => {%template (name => links);}p,
83     content => {
84     %section (level=>2,
85     title => {%res (name => {Error:Title});}p, heading,
86     content => {%paragraph (
87     content => {%res (name => {Error:Description});}p,
88     );%error-list (
89 wakaba 1.6 id => err--error,
90 wakaba 1.1 no-error => {%res (name => {Error:NoErrorReported});}p,
91     );}p,
92     );
93     }p,
94     );
95    
96 wakaba 1.6 ViewFragment:
97     @Name: err--general-error
98     @Description:
99     @@@:
100     General error reporting view template.
101     \
102     Usually, error reporting view use this fragment like
103     %template (name => err--general-error, -web-page-title => title,
104     -section-title => title, -content => error-message);.
105     @@lang: en
106     @Formatting:
107     %html-document (
108     title => {%apply-template (name => web-page-title);}p,
109 wakaba 1.7 link-meta => {%template (name => links);
110     %html-meta(name => ROBOTS, content => NOINDEX);}p,
111 wakaba 1.6 content => {
112     %block (id => tools1, class => tools,
113     content => {%template (name => navbar);}p);
114     %section (
115     title => {%apply-template (name => section-title);}p, heading,
116     content => {%apply-template (name => content);}p,
117     );
118     %section (
119     id => err--error,
120     title => {%res (name => {Error:Title});}p, heading,
121     content => {%error-list;}p,
122     );
123     %block (id => footer, content => {%template (name => ws--footer);}p);
124     }p,
125     );
126    
127 wakaba 1.3 ## TODO: Using general "structure"
128     ## Customizable HTTP status
129     ## Auto exiting
130    
131 wakaba 1.1 ViewFragment:
132     @Name: ws--post-content
133     @Description:
134     @@@: After content body -- error report
135     @@lang:en
136     @Order: 850
137     @Formatting:
138 wakaba 1.6 %section (
139     id => err--error,
140 wakaba 1.1 title => {%res (name => {Error:Title});}p, heading,
141     content => {%error-list;}p,
142     );
143    
144     ViewDefinition:
145     @Mode: -error-error
146     @Condition:
147     @@http-method[list]:
148     GET
149     HEAD
150     @Description:
151     @@@:
152     Error reporting special "view" used when "-error" also problematic
153     @@lang: en
154     @method:
155     @@Name:main
156     @@@:
157 wakaba 1.4 require SuikaWiki::Output::HTTP;
158     my $wiki = $self->{view}->{wiki};
159     $opt2->{output} = SuikaWiki::Output::HTTP->new
160     (wiki => $wiki,
161     view => $self->{view}, viewobj => $self);
162     $opt2->{output}->{status_code} = 500;
163     $opt2->{output}->{status_phrase} = q#Internal WikiEngine Error#;
164     $opt2->{output}->{entity}->{media_type} = q#text/html#;
165     ## ISSUE: Is this good? Or, should we try to convert UTF-8 or something?
166     $opt2->{output}->{entity}->{charset}
167     = $wiki->{config}->{charset}->{internal};
168     $opt2->{output}->set_expires
169     (%{$wiki->{config}->{entity}->{expires}->{error}});
170    
171     my $html = new Message::Markup::XML::Node
172     (type => '#element',
173     namespace_uri => $NS_XHTML1,
174     local_name => 'html');
175     $html->append_new_node (type => '#element',
176     namespace_uri => $NS_XHTML1,
177     local_name => 'head')
178     ->append_new_node (type => '#element',
179     namespace_uri => $NS_XHTML1,
180     local_name => 'title')
181     ->append_text ($WIKIRESOURCE->get (name => 'Error:Error:WebPageTitle',
182     wiki => $wiki,
183     default => '500 Internal WikiEngine Error'));
184    
185 wakaba 1.1 my $body = $html->append_new_node (type => '#element',
186     namespace_uri => $NS_XHTML1,
187     local_name => 'body');
188     $body->append_new_node (type => '#element',
189     namespace_uri => $NS_XHTML1,
190     local_name => 'h1')
191 wakaba 1.4 ->append_text ($WIKIRESOURCE->get (name => 'Error:Error:Title',
192     wiki => $wiki,
193     default => 'Internal WikiEngine Error'));
194 wakaba 1.1
195     $body->append_new_node (type => '#element',
196     namespace_uri => $NS_XHTML1,
197     local_name => 'p')
198 wakaba 1.4 ->append_text ($WIKIRESOURCE->get (name => 'Error:Description',
199     wiki => $wiki,
200     default => 'The WikiEngine encounted internal error and/or misconfiguration, and was unable to complete your request.'));
201 wakaba 1.1 $body->append_new_node (type => '#element',
202     namespace_uri => $NS_XHTML1,
203     local_name => 'p')
204 wakaba 1.4 ->append_text ($WIKIRESOURCE->get (name => 'Error:Error:Description',
205     wiki => $wiki,
206     default => 'Additionally, another error was encounted while trying to report that error.'));
207 wakaba 1.1
208     my $ol = $body->append_new_node (namespace_uri => $NS_XHTML1,
209     local_name => 'ol',
210     type => '#element');
211     for (@{$self->{view}->{wiki}->{var}->{error}||[]}) {
212     my $li = $ol->append_new_node (type => '#element',
213     namespace_uri => $NS_XHTML1,
214     local_name => 'li');
215     $li->append_node ($_->{description}, node_or_text => 1);
216     }
217    
218     $opt2->{output}->{entity}->{body} = $html->stringify;
219     $opt2->{output}->output (output => 'http-cgi');
220    
221     FormattingRule:
222     @Category[list]:
223     view
224     view-resource
225     @Name: error-list
226     @Description:
227     @@@: Listing reported errors
228     @@lang:en
229     @Parameter:
230     @@Name: no-error
231     @@Type: node
232     @@Default: ""
233     @@Description:
234     @@@@: List item text to be inserted if no error reported
235     @@@lang:en
236     @Formatting:
237     my $ol = ref ($p->{-parent})->new (namespace_uri => $NS_XHTML1,
238     local_name => 'ol',
239     type => '#element');
240     for (@{$o->{wiki}->{var}->{error}||[]}) {
241     my $li = $ol->append_new_node (type => '#element',
242     namespace_uri => $NS_XHTML1,
243     local_name => 'li');
244     $li->append_node ($_->{description}, node_or_text => 1);
245     }
246 wakaba 1.2 $o->{wiki}->{var}->{error} = [];
247 wakaba 1.1 if ($ol->count == 0) {
248     my $no_error = __ATTRNODE:%no_error__;
249     $ol->append_new_node
250     (type => '#element',
251     namespace_uri => $NS_XHTML1,
252     local_name => 'li')
253     ->append_node ($no_error) if $no_error->count;
254     }
255     $p->{-parent}->append_node ($ol) if $ol->count;
256    
257     Function:
258     @Name: make_caller_trace_table
259     @Description:
260     @@@: Generating an HTML table of caller stack trace
261     @@lang:en
262     @Main:
263     my (undef, $parent, $opt) = @_;
264 wakaba 1.4 my $tbl = $parent->append_new_node
265     (type => '#element',
266 wakaba 1.1 namespace_uri => $NS_XHTML1,
267     local_name => 'table')
268     ->append_new_node (type => '#element',
269     namespace_uri => $NS_XHTML1,
270     local_name => 'tbody');
271 wakaba 1.4 for (my $i = $opt->{skip};; $i++) {
272     my @caller = caller ($i);
273     last unless @caller;
274 wakaba 1.1 my $tr = $tbl->append_new_node (type => '#element',
275     namespace_uri => $NS_XHTML1,
276     local_name => 'tr');
277 wakaba 1.4 for (@caller) {
278 wakaba 1.1 $tr->append_new_node (type => '#element',
279     namespace_uri => $NS_XHTML1,
280     local_name => 'td')
281     ->append_text ($_);
282     }
283     }
284    
285     Function:
286     @Name: report_error_simple
287     @Description:
288     @@@:
289     Simple reporter of error encounted while processing formatting rules
290     @@lang:en
291     @Main:
292     my (undef, $wiki) = (shift, shift);
293     my $error = {};
294     my $dl = $error->{description}
295     = new Message::Markup::XML::Node
296     (type => '#element',
297     namespace_uri => $NS_XHTML1,
298     local_name => 'dl');
299     my %opt;
300     while (@_) {
301     my ($name, $val) = (shift, shift);
302     if (substr ($name, 0, 1) eq '-') {
303     $opt{$name} = $val;
304     next;
305     }
306     $dl->append_new_node (type => '#element',
307     namespace_uri => $NS_XHTML1,
308     local_name => 'dt')
309 wakaba 1.6 ->append_node ($name, node_or_text => 1);
310 wakaba 1.1 $dl->append_new_node (type => '#element',
311     namespace_uri => $NS_XHTML1,
312     local_name => 'dd')
313 wakaba 1.6 ->append_node ($val, node_or_text => 1);
314 wakaba 1.1 }
315     if ($opt{-trace}) {
316     $dl->append_new_node (type => '#element',
317     namespace_uri => $NS_XHTML1,
318     local_name => 'dt')
319 wakaba 1.4 ->append_text ($WIKIRESOURCE->get (name => 'Error:Call Stack Trace',
320     wiki => $wiki));
321 wakaba 1.1 __FUNCPACK__->make_caller_trace_table
322     ($dl->append_new_node (type => '#element',
323     namespace_uri => $NS_XHTML1,
324     local_name => 'dd'),
325     {skip => 2});
326     }
327     push @{$wiki->{var}->{error}||=[]}, $error;
328    
329     Function:
330     @Name: reporting_formatting_template_error
331     @Description:
332     @@@:
333 wakaba 1.4 Reporting formatting-template-text error.
334 wakaba 1.1 @Main:
335 wakaba 1.3 my (undef, $err, $wiki, %opt) = @_;
336 wakaba 1.1 my $error = {};
337     my $dl = $error->{description}
338     = new Message::Markup::XML::Node
339     (type => '#element',
340     namespace_uri => $NS_XHTML1,
341     local_name => 'dl');
342 wakaba 1.4 if ($opt{template}) {
343     $dl->append_new_node (type => '#element',
344     namespace_uri => $NS_XHTML1,
345     local_name => 'dt')
346     ->append_text ($WIKIRESOURCE->get (name => 'Error:Formatter:Template',
347     wiki => $wiki));
348     $dl->append_new_node (type => '#element',
349     namespace_uri => $NS_XHTML1,
350     local_name => 'dd')
351     ->append_text ($opt{template});
352     }
353 wakaba 1.1 $dl->append_new_node (type => '#element',
354     namespace_uri => $NS_XHTML1,
355     local_name => 'dt')
356 wakaba 1.4 ->append_text ($WIKIRESOURCE->get (name => 'Error:Condition',
357     wiki => $wiki));
358 wakaba 1.1 $dl->append_new_node (type => '#element',
359     namespace_uri => $NS_XHTML1,
360     local_name => 'dd')
361     ->append_text ($err->text);
362     $dl->append_new_node (type => '#element',
363     namespace_uri => $NS_XHTML1,
364     local_name => 'dt')
365 wakaba 1.4 ->append_text ($WIKIRESOURCE->get (name => 'Error:Formatter:Context',
366     wiki => $wiki));
367 wakaba 1.1 $dl->append_new_node (type => '#element',
368     namespace_uri => $NS_XHTML1,
369     local_name => 'dd')
370 wakaba 1.3 ->append_text (qq($err->{-object}->{-category_name}));
371     if ($opt{trace}) {
372     $dl->append_new_node (type => '#element',
373     namespace_uri => $NS_XHTML1,
374     local_name => 'dt')
375 wakaba 1.4 ->append_text ($WIKIRESOURCE->get (name => 'Error:Call Stack Trace',
376     wiki => $wiki));
377 wakaba 1.3 __FUNCPACK__->make_caller_trace_table
378     ($dl->append_new_node (type => '#element',
379     namespace_uri => $NS_XHTML1,
380     local_name => 'dd'),
381     {skip => 2});
382     }
383 wakaba 1.1 push @{$wiki->{var}->{error}||=[]}, $error;
384    
385 wakaba 1.7 FormattingRule:
386     @Category[list]:
387     view
388     view-resource
389     @Name: err--http-status-code
390     @Description:
391     @@@: Current HTTP status code if available.
392     @@lang: en
393     @Parameter:
394     @@Name: default
395     @@Type: <<3DIGIT>>
396     @@Default: "500"
397     @@Description:
398     @@@@:
399     Default status code returned when HTTP status code unavailable.
400     The reason default of default is "500" is this formatting rule is
401     defined in Error plugin module:-).
402     @@@lang: en
403     @Formatting:
404     $p->{-parent}->append_text (0+$o->{var}->{wv__output}->{status_code});
405    
406 wakaba 1.1 Resource:
407 wakaba 1.4 @Error:Call Stack Trace:
408     @@@: Function call stack trace
409     @@lang: en
410     @Error:Condition:
411     @@@: Error condition
412     @@lang: en
413 wakaba 1.1 @Error:Description:
414     @@@:
415 wakaba 1.3 The WikiEngine encounted internal error and/or misconfiguration, and
416 wakaba 1.1 was unable to complete your request.
417 wakaba 1.3 Please contact the administrator of this wiki with reported errors
418     below.
419 wakaba 1.1 @@lang:en
420 wakaba 1.4 @Error:Detail:
421     @@@: Detail
422     @@lang: en
423     @Error:Error:Description:
424     @@@:
425     Additionally, another error was encounted while trying to report
426     that error.
427     @@lang: en
428     @Error:Error:Title:
429     @@@: Internal WikiEngine Error
430     @@lang: en
431     @Error:Error:WebPageTitle:
432 wakaba 1.7 @@@: %err--http-status-code; Internal WikiEngine Error (%page-name;)
433 wakaba 1.4 @@lang: en
434     @Error:Formatter:Context:
435     @@@: Formatting template evaluation context
436     @@lang: en
437     @Error:Formatter:Template:
438     @@@: Broken formatting template
439     @@lang: en
440 wakaba 1.1 @Error:NoErrorReported:
441     @@@: No error reported
442     @@lang:en
443     @Error:Title:
444     @@@: Internal WikiEngine Error
445     @@lang:en
446     @Error:WebPageTitle:
447     @@@: %page-name; (Error)
448     @@lang:en
449    

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24