/[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.4 - (hide annotations) (download)
Sun Feb 1 12:13:36 2004 UTC (22 years, 6 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +93 -37 lines
More resource'ization

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24