Skip to content

Commit

Permalink
More error message fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Mar 22, 2023
1 parent a40562d commit cae09ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion graphql-c_parser/lib/graphql/c_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def self.prepare_parse_error(message, parser)
end
end

message.sub!(/, unexpected ([a-zA-Z ]+),/, ", unexpected \\1 (#{token[3].inspect}),")
if !message.include?("end of file")
message.sub!(/, unexpected ([a-zA-Z ]+)(,| at)/, ", unexpected \\1 (#{token[3].inspect})\\2")
end

GraphQL::ParseError.new(message, line, col, parser.query_string, filename: parser.filename)
end
Expand Down
18 changes: 15 additions & 3 deletions spec/graphql/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,24 @@ def self.after_query(q)
it "adds an entry to the errors key" do
res = schema.execute(" { ")
assert_equal 1, res["errors"].length
assert_equal "Unexpected end of document", res["errors"][0]["message"]
assert_equal [], res["errors"][0]["locations"]
if USING_C_PARSER
expected_err = "syntax error, unexpected end of file at [1, 2]"
expected_locations = [{"line" => 1, "column" => 2}]
else
expected_err = "Unexpected end of document"
expected_locations = []
end
assert_equal expected_err, res["errors"][0]["message"]
assert_equal expected_locations, res["errors"][0]["locations"]

res = schema.execute(invalid_query_string)
assert_equal 1, res["errors"].length
assert_equal %|Parse error on "1" (INT) at [4, 26]|, res["errors"][0]["message"]
expected_error = if USING_C_PARSER
"syntax error, unexpected INT (\"1\") at [4, 26]"
else
%|Parse error on "1" (INT) at [4, 26]|
end
assert_equal expected_error, res["errors"][0]["message"]
assert_equal({"line" => 4, "column" => 26}, res["errors"][0]["locations"][0])
end

Expand Down

0 comments on commit cae09ec

Please sign in to comment.