GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Hongli Lai (Phusion) (author)
Sat May 10 03:29:52 -0700 2008
commit  b137282e73bd518d249dc19e5cd17ead933f91b9
tree    50b0b7f7fff3624d716c2242a892a653052df3f0
parent  d31dc2d7f28cef553ae480c6216ecd87ef766ed4
passenger / misc / render_error_pages.rb
100755 109 lines (92 sloc) 3.091 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env ruby
# Phusion Passenger - http://www.modrails.com/
# Copyright (C) 2008 Phusion
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
$LOAD_PATH << "#{File.dirname(__FILE__)}/../lib"
require 'passenger/html_template'
require 'passenger/spawn_manager'
require 'passenger/platform_info'
include Passenger
 
if !defined?(Mysql::Error)
  module Mysql
    class Error < StandardError
    end
  end
end
 
def create_dummy_exception
  begin
    raise StandardError, "A dummy exception."
  rescue => e
    return e
  end
end
 
def create_database_exception
  begin
    raise Mysql::Error, "Cannot connect to database localhost:12345: connection refused (1234)"
  rescue => e
    return e
  end
end
 
def create_dummy_backtrace
  dummy_backtrace = nil
  begin
    raise StandardError, "A dummy exception."
  rescue => e
    dummy_backtrace = e.backtrace
  end
  dummy_backtrace.unshift("/webapps/foo/app/models/Foo.rb:102:in `something`")
  dummy_backtrace.unshift("/webapps/foo/config/environment.rb:10")
  return dummy_backtrace
end
 
def render_error_page(exception, output, template)
  exception.set_backtrace(create_dummy_backtrace)
  File.open(output, 'w') do |f|
    template = HTMLTemplate.new(template,
      :error => exception, :app_root => "/foo/bar")
    f.write(template.result)
    puts "Written '#{output}'"
  end
end
 
def start
  bt = create_dummy_backtrace
  
  e = FrameworkInitError.new("Some error message",
    create_dummy_exception,
    :vendor => '/webapps/foo')
  render_error_page(e, 'framework_init_error_with_vendor.html',
    'framework_init_error')
  
  e = FrameworkInitError.new("Some error message",
    create_dummy_exception,
    :version => '1.2.3')
  render_error_page(e, 'framework_init_error.html',
    'framework_init_error')
  
  e = VersionNotFound.new("Some error message", '>= 1.0.2')
  render_error_page(e, 'version_not_found.html',
    'version_not_found')
  
  e = AppInitError.new("Some error message", create_dummy_exception)
  render_error_page(e, 'app_init_error.html',
    'app_init_error')
  
  e = AppInitError.new("Some error message", create_database_exception)
  render_error_page(e, 'database_error.html',
    'database_error')
  
  e = ArgumentError.new("Some error message")
  render_error_page(e, 'invalid_app_root.html',
    'invalid_app_root')
  
  e = StandardError.new("Some error message")
  render_error_page(e, 'general_error.html',
    'general_error')
  
  e = StandardError.new("Some error message")
  render_error_page(e, 'app_exited.html', 'app_exited_during_initialization')
end
 
start