C0 code coverage information
Generated on Sat Feb 02 17:44:25 +0100 2008 with rcov 0.8.1.2
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1 # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
2 # All files in this distribution are subject to the terms of the Ruby license.
3
4 module Ramaze
5 module Dispatcher
6
7 # Last resort dispatcher, tries to recover as much information as possible
8 # from the past request and takes the appropiate actions.
9 #
10 # You can configure it over the HANDLE_ERROR constant or by defining error
11 # actions in your controllers.
12
13 class Error
14
15 # The class of exception is matched when an error occurs and the status
16 # code is set. The absolute URLs are used as fallback in case of a total
17 # failure.
18 HANDLE_ERROR = {
19 Exception => [ 500, '/error' ],
20 Ramaze::Error::NoAction => [ 404, '/error' ],
21 Ramaze::Error::NoController => [ 404, '/error' ],
22 }
23
24 class << self
25 trait :last_error => nil
26
27 # Takes exception, of metainfo only :controller is used at the moment.
28 # Then goes on to try and find the correct response status and path.
29 # In case metainfo has a controller we try to get the action for the
30 # path on it, dispatching there if we find one.
31 # Otherwise a plain-text error message is set as response.
32 def process(error, metainfo = {})
33 log_error(error)
34
35 Thread.current[:exception] = error
36 response = Response.current
37
38 key = error.class.ancestors.find{|a| HANDLE_ERROR[a]}
39 status, path = *HANDLE_ERROR[key || Exception]
40 status ||= 500
41
42 if controller = metainfo[:controller]
43 newpath = (controller.mapping + path).squeeze('/')
44 action_response = Dispatcher::Action.process(newpath)
45 case action_response
46 when Ramaze::Error
47 Inform.debug("No custom error page found on #{controller}, going to #{path}")
48 else
49 action_response.status = status
50 return action_response
51 end
52 end
53
54 if path and Global.error_page and error.message !~ /`#{path}'/
55 response.status = status
56 return Dispatcher.dispatch_to(path)
57 else
58 response.build(error.message, status)
59 end
60 rescue Object => ex
61 Inform.error(ex)
62 response.build(ex.message, status)
63 end
64
65 # Only logs new errors with full backtrace, repeated errors are shown
66 # only with their message.
67 def log_error error
68 error_message = error.message
69
70 if trait[:last_error] == error_message or error.is_a? Ramaze::Error::NoAction
71 Inform.error(error_message)
72 else
73 trait[:last_error] = error_message
74 Inform.error(error)
75 end
76 end
77
78 # Handle to current exception.
79 # Only works inside request/response cycle.
80 def current
81 Thread.current[:exception]
82 end
83
84 end
85 end
86 end
87 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.