Skip to content
This repository was archived by the owner on Dec 2, 2018. It is now read-only.

Commit 551a33f

Browse files
committed
Output command run for easier debugging.
1 parent c8113e6 commit 551a33f

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/rack/legacy/cgi.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'fileutils'
22
require 'tempfile'
3+
require 'shellwords'
34
require 'rack/legacy/error_page'
45

56
module Rack
@@ -75,7 +76,12 @@ def run(env, *path)
7576
Process.wait
7677
unless $?.exitstatus == 0
7778
status = 500
78-
body = ErrorPage.new(env, headers, body, stderr).to_s
79+
cmd = env.inject(path) do |assignments, (key, value)|
80+
assignments.unshift "#{key}=#{value.to_s.shellescape}" if
81+
value.respond_to?(:to_str) && key =~ /^[A-Z_]+$/
82+
assignments
83+
end * ' '
84+
body = ErrorPage.new(env, headers, body, stderr, cmd).to_s
7985
headers = {'Content-Type' => 'text/html'}
8086
end
8187
end

lib/rack/legacy/error_page.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ class ErrorPage
77

88
# Given the environment, stdout and stderr from a programs execution
99
# will generate a error page to assist in debugging
10-
def initialize(env, headers, stdout, stderr)
10+
def initialize(env, headers, stdout, stderr, cmd=nil)
1111
@env = env
1212
@headers = headers
1313
@stdout = stdout
1414
@stderr = stderr
15+
@cmd = cmd
1516
end
1617

1718
# Generate the page
@@ -46,17 +47,22 @@ def template
4647
4748
<p>An error was encountered while executing
4849
<%=h @env['PATH_INFO'].to_s %> under the rack-legacy middleware.</p>
49-
50+
51+
<% if @cmd %>
52+
<p>To run this from the command line use the following command.</p>
53+
<pre><code><%= @cmd %></code></pre>
54+
<% end %>
55+
5056
<% unless @stdout == '' %>
5157
<h2>Standard Out</h2>
5258
<pre><code><%=h @stdout %></code></pre>
5359
<% end %>
54-
60+
5561
<% unless @stderr == '' %>
5662
<h2>Standard Error</h2>
5763
<pre><code><%=h @stderr %></code></pre>
5864
<% end %>
59-
65+
6066
<% unless @headers.empty? %>
6167
<h2>Output Headers</h2>
6268
<table>
@@ -68,7 +74,7 @@ def template
6874
<% end %>
6975
</table>
7076
<% end %>
71-
77+
7278
<% unless @env.empty? %>
7379
<h2>Environment</h2>
7480
<table>

0 commit comments

Comments
 (0)