Skip to content

Commit

Permalink
fix: Format the error backtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
rzane committed Jan 14, 2022
1 parent b0a21af commit a23620f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/functions_framework/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ def interpret_response response
when ::CloudEvents::CloudEventsError
cloud_events_error_response response
when ::StandardError
error_response "#{response.class}: #{response.message}\n#{response.backtrace}\n"
message = "#{response.class}: #{response.message}"
message = [message, *response.backtrace].join "\n\t"
error_response message
else
error_response "Unexpected response type: #{response.class}"
end
Expand Down
3 changes: 2 additions & 1 deletion lib/functions_framework/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ def interpret_response
json = ::JSON.dump response
string_response json, 200, content_type: "application/json"
when ::StandardError
message = "#{response.class}: #{response.message}\n#{response.backtrace}\n"
message = "#{response.class}: #{response.message}"
message = [message, *response.backtrace].join "\n\t"
string_response message, 500
else
raise "Unexpected response type: #{response.inspect}"
Expand Down
2 changes: 1 addition & 1 deletion test/test_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def query_server_with_retry server
::Net::HTTP.get_response URI("#{server_url}/")
end
assert_equal "500", response.code
assert_match(/Whoops!/, response.body)
assert_match(/RuntimeError: Whoops!\n\t#{__FILE__}/, response.body)
assert_equal "text/plain; charset=utf-8", response["Content-Type"]
end

Expand Down

0 comments on commit a23620f

Please sign in to comment.