Skip to content

Commit 1cc8dfb

Browse files
committed
shorten error messages
Before: Template render error: File "reference.mustache", line 10, characters 2-17: the variable 'group.first' is missing. Parse error: File "eof-before-unescape.mustache", line 2, character 0: ident expected. After: File "reference.mustache", line 10, characters 2-17: the variable 'group.first' is missing. File "eof-before-unescape.mustache", line 2, character 0: ident expected. I find that the removed headers did not add much information: the nature of the error is rather clear from the error message anyway.
1 parent b8e6716 commit 1cc8dfb

File tree

4 files changed

+2
-30
lines changed

4 files changed

+2
-30
lines changed

bin/mustache_cli.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let load_template template_filename =
2929
in
3030
try Mustache.parse_lx lexbuf
3131
with Mustache.Parse_error err ->
32-
Format.eprintf "Parse error:@\n%a@."
32+
Format.eprintf "%a@."
3333
Mustache.pp_template_parse_error err;
3434
exit 3
3535

@@ -49,7 +49,7 @@ let run search_path json_filename template_filename =
4949
print_string output;
5050
flush stdout
5151
with Mustache.Render_error err ->
52-
Format.eprintf "Template render error:@\n%a@."
52+
Format.eprintf "%a@."
5353
Mustache.pp_render_error err;
5454
exit 2
5555

bin/test/errors/parsing-errors.t

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,61 @@ Delimiter problems:
44
$ PROBLEM=no-closing-mustache.mustache
55
$ echo "{{foo" > $PROBLEM
66
$ mustache foo.json $PROBLEM
7-
Parse error:
87
File "no-closing-mustache.mustache", line 2, character 0: '}}' expected.
98
[3]
109
1110
$ PROBLEM=one-closing-mustache.mustache
1211
$ echo "{{foo}" > $PROBLEM
1312
$ mustache foo.json $PROBLEM
14-
Parse error:
1513
File "one-closing-mustache.mustache", line 1, character 5: '}}' expected.
1614
[3]
1715
1816
$ PROBLEM=eof-before-variable.mustache
1917
$ echo "{{" > $PROBLEM
2018
$ mustache foo.json $PROBLEM
21-
Parse error:
2219
File "eof-before-variable.mustache", line 2, character 0: ident expected.
2320
[3]
2421
2522
$ PROBLEM=eof-before-section.mustache
2623
$ echo "{{#" > $PROBLEM
2724
$ mustache foo.json $PROBLEM
28-
Parse error:
2925
File "eof-before-section.mustache", line 2, character 0: ident expected.
3026
[3]
3127
3228
$ PROBLEM=eof-before-section-end.mustache
3329
$ echo "{{#foo}} {{.}} {{/" > $PROBLEM
3430
$ mustache foo.json $PROBLEM
35-
Parse error:
3631
File "eof-before-section-end.mustache", line 2, character 0: ident expected.
3732
[3]
3833
3934
$ PROBLEM=eof-before-inverted-section.mustache
4035
$ echo "{{^" > $PROBLEM
4136
$ mustache foo.json $PROBLEM
42-
Parse error:
4337
File "eof-before-inverted-section.mustache", line 2, character 0:
4438
ident expected.
4539
[3]
4640
4741
$ PROBLEM=eof-before-unescape.mustache
4842
$ echo "{{{" > $PROBLEM
4943
$ mustache foo.json $PROBLEM
50-
Parse error:
5144
File "eof-before-unescape.mustache", line 2, character 0: ident expected.
5245
[3]
5346
5447
$ PROBLEM=eof-before-unescape.mustache
5548
$ echo "{{&" > $PROBLEM
5649
$ mustache foo.json $PROBLEM
57-
Parse error:
5850
File "eof-before-unescape.mustache", line 2, character 0: ident expected.
5951
[3]
6052
6153
$ PROBLEM=eof-before-partial.mustache
6254
$ echo "{{>" > $PROBLEM
6355
$ mustache foo.json $PROBLEM
64-
Parse error:
6556
File "eof-before-partial.mustache", line 2, character 0: '}}' expected.
6657
[3]
6758
6859
$ PROBLEM=eof-in-comment.mustache
6960
$ echo "{{! non-terminated comment" > $PROBLEM
7061
$ mustache foo.json $PROBLEM
71-
Parse error:
7262
File "eof-in-comment.mustache", line 2, character 0: non-terminated comment.
7363
[3]
7464
@@ -78,14 +68,12 @@ Mismatches between opening and closing mustaches:
7868
$ PROBLEM=two-three.mustache
7969
$ echo "{{ foo }}}" > $PROBLEM
8070
$ mustache foo.json $PROBLEM
81-
Parse error:
8271
File "two-three.mustache", line 1, characters 7-10: '}}' expected.
8372
[3]
8473
8574
$ PROBLEM=three-two.mustache
8675
$ echo "{{{ foo }}" > $PROBLEM
8776
$ mustache foo.json $PROBLEM
88-
Parse error:
8977
File "three-two.mustache", line 1, characters 8-10: '}}}' expected.
9078
[3]
9179
@@ -95,22 +83,19 @@ Mismatch between section-start and section-end:
9583
$ PROBLEM=foo-bar.mustache
9684
$ echo "{{#foo}} {{.}} {{/bar}}" > $PROBLEM
9785
$ mustache foo.json $PROBLEM
98-
Parse error:
9986
File "foo-bar.mustache", line 1, characters 0-23:
10087
Section mismatch: {{#foo}} is closed by {{/bar}}.
10188
[3]
10289
10390
$ PROBLEM=foo-not-closed.mustache
10491
$ echo "{{#foo}} {{.}} {{foo}}" > $PROBLEM
10592
$ mustache foo.json $PROBLEM
106-
Parse error:
10793
File "foo-not-closed.mustache", line 2, character 0: syntax error.
10894
[3]
10995
11096
$ PROBLEM=wrong-nesting.mustache
11197
$ echo "{{#bar}} {{#foo}} {{.}} {{/bar}} {{/foo}}" > $PROBLEM
11298
$ mustache foo.json $PROBLEM
113-
Parse error:
11499
File "wrong-nesting.mustache", line 1, characters 9-32:
115100
Section mismatch: {{#foo}} is closed by {{/bar}}.
116101
[3]
@@ -121,6 +106,5 @@ Weird cases that may confuse our lexer or parser:
121106
$ PROBLEM=weird-tag-name.mustache
122107
$ echo "{{.weird}} foo bar" > $PROBLEM
123108
$ mustache foo.json $PROBLEM
124-
Parse error:
125109
File "weird-tag-name.mustache", line 1, character 3: '}}' expected.
126110
[3]

bin/test/errors/render-errors.t/run.t

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,67 +27,57 @@ one possible source of error, or both, or none.
2727
Invalid variable name:
2828

2929
$ mustache reference.json missing-variable.mustache
30-
Template render error:
3130
File "missing-variable.mustache", line 14, characters 40-46:
3231
the variable 'na' is missing.
3332
[2]
3433

3534
$ mustache missing-variable.json reference.mustache
36-
Template render error:
3735
File "reference.mustache", line 5, characters 4-12:
3836
the variable 'data' is missing.
3937
[2]
4038

4139
Invalid section name:
4240

4341
$ mustache reference.json missing-section.mustache
44-
Template render error:
4542
File "missing-section.mustache", line 14, characters 0-55:
4643
the section 'na' is missing.
4744
[2]
4845

4946
$ mustache missing-section.json reference.mustache
50-
Template render error:
5147
File "reference.mustache", lines 9-12, characters 0-10:
5248
the section 'group' is missing.
5349
[2]
5450

5551
Error in a dotted path foo.bar (one case for the first component, the other in the second).
5652

5753
$ mustache reference.json invalid-dotted-name-1.mustache
58-
Template render error:
5954
File "invalid-dotted-name-1.mustache", line 10, characters 2-15:
6055
the variable 'gro' is missing.
6156
[2]
6257

6358
$ mustache invalid-dotted-name-1.json reference.mustache
64-
Template render error:
6559
File "reference.mustache", lines 9-12, characters 0-10:
6660
the section 'group' is missing.
6761
[2]
6862

6963
$ mustache reference.json invalid-dotted-name-2.mustache
70-
Template render error:
7164
File "invalid-dotted-name-2.mustache", line 10, characters 2-15:
7265
the variable 'group.fir' is missing.
7366
[2]
7467

7568
$ mustache invalid-dotted-name-2.json reference.mustache
76-
Template render error:
7769
File "reference.mustache", line 10, characters 2-17:
7870
the variable 'group.first' is missing.
7971
[2]
8072

8173
Non-scalar used as a scalar:
8274

8375
$ mustache reference.json non-scalar.mustache
84-
Template render error:
8576
File "non-scalar.mustache", line 4, characters 0-8:
8677
the value of 'list' is not a valid scalar.
8778
[2]
8879

8980
$ mustache non-scalar.json reference.mustache
90-
Template render error:
9181
File "reference.mustache", line 1, characters 7-16:
9282
the value of 'title' is not a valid scalar.
9383
[2]
@@ -98,7 +88,6 @@ Missing partial (currently the CLI does not support any partial anyway):
9888
in better `ls` output).
9989

10090
$ mustache reference.json z-missing-partial.mustache
101-
Template render error:
10291
File "z-missing-partial.mustache", line 11, characters 2-13:
10392
the partial 'second' is missing.
10493
[2]

bin/test/partials.t/run.t

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ we need to set the search path to locate their included partials.
2121

2222
This fails:
2323
$ (cd subdir; mustache ../data.json ../foo.mustache)
24-
Template render error:
2524
File "../foo.mustache", line 2, characters 23-31:
2625
the partial 'bar' is missing.
2726
[2]

0 commit comments

Comments
 (0)