Skip to content

Commit

Permalink
Improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Nov 27, 2023
1 parent 69e8339 commit f7f6d6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/controllers/pg_hero/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,10 @@ def explain
@error =
if message == "Unsafe statement"
"Unsafe statement"
elsif message.start_with?("PG::UndefinedParameter") || message.include?("EXPLAIN options ANALYZE and GENERIC_PLAN cannot be used together")
elsif message.start_with?("PG::UndefinedParameter")
"Can't explain queries with bind parameters"
elsif message.include?("EXPLAIN options ANALYZE and GENERIC_PLAN cannot be used together")
"Can't analyze queries with bind parameters"
elsif message.start_with?("PG::SyntaxError")
"Syntax error with query"
elsif message.start_with?("PG::QueryCanceled")
Expand Down
6 changes: 5 additions & 1 deletion test/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ def test_explain_analyze_normalized
post pg_hero.explain_path, params: {query: "SELECT $1", commit: "Analyze"}
end
assert_response :success
assert_match "Can't explain queries with bind parameters", response.body
if explain_normalized?
assert_match "Can't analyze queries with bind parameters", response.body
else
assert_match "Can't explain queries with bind parameters", response.body
end
end

def test_explain_analyze_timeout
Expand Down

0 comments on commit f7f6d6d

Please sign in to comment.