Skip to content

Commit d0d0322

Browse files
committed
print_error: Make location formatting IDE friendly
This is the format used by jest, flow, typescript, and many others. Replicates graphql/graphql-js@b42f8c8
1 parent 9e18827 commit d0d0322

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

graphql/error/print_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def highlight_source_at_location(source: "Source", location: "SourceLocation") -
6060
def get_line(index: int) -> Optional[str]:
6161
return lines[index] if 0 <= index < len_lines else None
6262

63-
return f"{source.name} ({line_num}:{column_num})\n" + print_prefixed_lines(
63+
return f"{source.name}:{line_num}:{column_num}\n" + print_prefixed_lines(
6464
[
6565
(f"{line_num - 1}: ", get_line(line_index - 1)),
6666
(f"{line_num}: ", get_line(line_index)),

tests/error/test_graphql_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def serializes_to_include_message():
9898
def serializes_to_include_message_and_locations():
9999
e = GraphQLError("msg", field_node)
100100
assert "msg" in str(e)
101-
assert "(2:3)" in str(e)
101+
assert ":2:3" in str(e)
102102
assert repr(e) == (
103103
"GraphQLError('msg', locations=[SourceLocation(line=2, column=3)])"
104104
)

tests/error/test_print_error.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def prints_line_numbers_with_correct_padding():
1919
"""
2020
Single digit line number with no padding
2121
22-
Test (9:1)
22+
Test:9:1
2323
9: *
2424
^
2525
"""
@@ -36,7 +36,7 @@ def prints_line_numbers_with_correct_padding():
3636
"""
3737
Left padded first line number
3838
39-
Test (9:1)
39+
Test:9:1
4040
9: *
4141
^
4242
10:\x20
@@ -86,13 +86,13 @@ def prints_an_error_with_nodes_from_different_sources():
8686
"""
8787
Example error with two nodes
8888
89-
SourceA (2:10)
89+
SourceA:2:10
9090
1: type Foo {
9191
2: field: String
9292
^
9393
3: }
9494
95-
SourceB (2:10)
95+
SourceB:2:10
9696
1: type Foo {
9797
2: field: Int
9898
^

tests/language/test_lexer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def errors_respect_whitespace():
6565
"""
6666
Syntax Error: Cannot parse the unexpected character '?'.
6767
68-
GraphQL request (3:5)
68+
GraphQL request:3:5
6969
2:\x20
7070
3: ?
7171
^
@@ -82,7 +82,7 @@ def updates_line_numbers_in_error_for_file_context():
8282
"""
8383
Syntax Error: Cannot parse the unexpected character '?'.
8484
85-
foo.js (13:6)
85+
foo.js:13:6
8686
12:\x20
8787
13: ?
8888
^
@@ -98,7 +98,7 @@ def updates_column_numbers_in_error_for_file_context():
9898
"""
9999
Syntax Error: Cannot parse the unexpected character '?'.
100100
101-
foo.js (1:5)
101+
foo.js:1:5
102102
1: ?
103103
^
104104
"""

tests/language/test_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def parse_provides_useful_errors():
7171
"""
7272
Syntax Error: Expected Name, found <EOF>
7373
74-
GraphQL request (1:2)
74+
GraphQL request:1:2
7575
1: {
7676
^
7777
"""
@@ -93,7 +93,7 @@ def parse_provides_useful_error_when_using_source():
9393
error = exc_info.value
9494
assert str(error) == (
9595
"Syntax Error: Expected {, found <EOF>\n\n"
96-
"MyQuery.graphql (1:6)\n1: query\n ^\n"
96+
"MyQuery.graphql:1:6\n1: query\n ^\n"
9797
)
9898

9999
def parses_variable_inline_values():

tests/utilities/test_strip_ignored_characters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def report_document_with_invalid_token():
133133
"""
134134
Syntax Error: Unterminated string.
135135
136-
GraphQL request (1:13)
136+
GraphQL request:1:13
137137
1: { foo(arg: "
138138
^
139139
2: "

0 commit comments

Comments
 (0)