Skip to content

Commit e326fff

Browse files
committed
Fix debug string in ParseError message
1 parent d24f518 commit e326fff

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/graphql/language/lexer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def debug_token_value(token_name)
130130
elsif token_name == :STRING
131131
string_value
132132
elsif @scanner.matched_size.nil?
133-
@scanner.peek(1)
133+
@string.byteslice(@scanner.pos - 1, 1)
134134
else
135135
token_value
136136
end

spec/graphql/language/parser_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,19 @@
235235
assert_equal expected_msg, err.message
236236
end
237237

238+
it "shows the right character in error messages" do
239+
err = assert_raises(GraphQL::ParseError) {
240+
GraphQL.parse("query # comment\n ~ { a b }")
241+
}
242+
expected_msg = if USING_C_PARSER
243+
"syntax error, unexpected invalid token (\"~\"), expecting LCURLY at [2, 2]"
244+
else
245+
"Expected NAME, actual: UNKNOWN_CHAR (\"~\") at [2, 2]"
246+
end
247+
248+
assert_equal expected_msg, err.message
249+
end
250+
238251
it "can reject name start at the end of numbers" do
239252
prev_reject_numers_followed_by_names = GraphQL.reject_numbers_followed_by_names
240253
GraphQL.reject_numbers_followed_by_names = false

0 commit comments

Comments
 (0)