Skip to content

Commit

Permalink
Only report the error message once (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfus authored Feb 5, 2024
1 parent 134c0da commit 9f10cf5
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 135 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,34 @@ The following errors are returned:
```
testdata/basic.proto3test.yaml:5:18: expected bool, got "1"
5 | - single_bool: 1
| ^...................... expected bool, got "1"
| .................^
testdata/basic.proto3test.yaml:6:18: expected bool, got "0"
6 | - single_bool: 0
| ^...................... expected bool, got "0"
| .................^
testdata/basic.proto3test.yaml:7:18: expected tag !!bool, got !!str
7 | - single_bool: "true"
| ^...................... expected tag !!bool, got !!str
| .................^
testdata/basic.proto3test.yaml:8:18: expected tag !!bool, got !!str
8 | - single_bool: "false"
| ^...................... expected tag !!bool, got !!str
| .................^
testdata/basic.proto3test.yaml:9:18: expected bool, got "True"
9 | - single_bool: True
| ^...................... expected bool, got "True"
| .................^
testdata/basic.proto3test.yaml:10:18: expected bool, got "False"
10 | - single_bool: False
| ^...................... expected bool, got "False"
| .................^
testdata/basic.proto3test.yaml:11:18: expected bool, got "TRUE"
11 | - single_bool: TRUE
| ^...................... expected bool, got "TRUE"
| .................^
testdata/basic.proto3test.yaml:12:18: expected bool, got "FALSE"
12 | - single_bool: FALSE
| ^...................... expected bool, got "FALSE"
| .................^
testdata/basic.proto3test.yaml:13:18: expected bool, got "yes"
13 | - single_bool: yes
| ^...................... expected bool, got "yes"
| .................^
testdata/basic.proto3test.yaml:14:18: expected bool, got "no"
14 | - single_bool: no
| ^...................... expected bool, got "no"
| .................^
```
Only `true` and `false` are valid values for the `single_bool` field.
Expand Down Expand Up @@ -138,7 +138,7 @@ The errors produced by the `Validator` will show up along side the ProtoYAML err
```
testdata/validate.validate.yaml:4:18 cases[2].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)
4 | - float_gt_lt: 10.5
| ^...................... cases[2].float_gt_lt: value must be greater than 0 and less than 10 (float.gt_lt)
| .................^
```

## Status: Beta
Expand Down
12 changes: 2 additions & 10 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,8 @@ func (n *nodeError) Error() string {
if n.line != "" {
lineNum := fmt.Sprintf("%4d", n.Node.Line)
result.WriteString(fmt.Sprintf("%s | %s\n", lineNum, n.line))
tailLen := len(n.line)
if tailLen < 40 {
tailLen = 40
}
tailLen -= n.Node.Column
if tailLen < 1 {
tailLen = 1
}
marker := strings.Repeat(" ", n.Node.Column-1) + "^" + strings.Repeat(".", tailLen)
result.WriteString(fmt.Sprintf("%s | %s %s\n", lineNum, marker, n.Unwrap().Error()))
marker := strings.Repeat(".", n.Node.Column-1) + "^"
result.WriteString(fmt.Sprintf("%s | %s\n", lineNum, marker))
}
return result.String()
}
Expand Down
118 changes: 59 additions & 59 deletions internal/testdata/basic.proto3test.txt
Original file line number Diff line number Diff line change
@@ -1,235 +1,235 @@
internal/testdata/basic.proto3test.yaml:7:18 expected bool, got "1"
7 | - single_bool: 1
7 | ^...................... expected bool, got "1"
7 | .................^

internal/testdata/basic.proto3test.yaml:8:18 expected bool, got "0"
8 | - single_bool: 0
8 | ^...................... expected bool, got "0"
8 | .................^

internal/testdata/basic.proto3test.yaml:9:18 expected tag !!bool, got !!str
9 | - single_bool: "true"
9 | ^...................... expected tag !!bool, got !!str
9 | .................^

internal/testdata/basic.proto3test.yaml:10:18 expected tag !!bool, got !!str
10 | - single_bool: "false"
10 | ^...................... expected tag !!bool, got !!str
10 | .................^

internal/testdata/basic.proto3test.yaml:11:18 expected bool, got "True"
11 | - single_bool: True
11 | ^...................... expected bool, got "True"
11 | .................^

internal/testdata/basic.proto3test.yaml:12:18 expected bool, got "False"
12 | - single_bool: False
12 | ^...................... expected bool, got "False"
12 | .................^

internal/testdata/basic.proto3test.yaml:13:18 expected bool, got "TRUE"
13 | - single_bool: TRUE
13 | ^...................... expected bool, got "TRUE"
13 | .................^

internal/testdata/basic.proto3test.yaml:14:18 expected bool, got "FALSE"
14 | - single_bool: FALSE
14 | ^...................... expected bool, got "FALSE"
14 | .................^

internal/testdata/basic.proto3test.yaml:15:18 expected bool, got "yes"
15 | - single_bool: yes
15 | ^...................... expected bool, got "yes"
15 | .................^

internal/testdata/basic.proto3test.yaml:16:18 expected bool, got "no"
16 | - single_bool: no
16 | ^...................... expected bool, got "no"
16 | .................^

internal/testdata/basic.proto3test.yaml:17:18 expected scalar, got sequence
17 | - single_bool: []
17 | ^...................... expected scalar, got sequence
17 | .................^

internal/testdata/basic.proto3test.yaml:18:18 expected scalar, got mapping
18 | - single_bool: {}
18 | ^...................... expected scalar, got mapping
18 | .................^

internal/testdata/basic.proto3test.yaml:25:19 integer is too large: > 2147483647
25 | - single_int32: 2147483648
25 | ^..................... integer is too large: > 2147483647
25 | ..................^

internal/testdata/basic.proto3test.yaml:26:19 integer is too small: < -2147483648
26 | - single_int32: -2147483649
26 | ^..................... integer is too small: < -2147483648
26 | ..................^

internal/testdata/basic.proto3test.yaml:29:19 integer is too large: > 2147483647
29 | - single_int32: 0X80000000
29 | ^..................... integer is too large: > 2147483647
29 | ..................^

internal/testdata/basic.proto3test.yaml:30:19 integer is too small: < -2147483648
30 | - single_int32: -0x80000001
30 | ^..................... integer is too small: < -2147483648
30 | ..................^

internal/testdata/basic.proto3test.yaml:33:19 integer is too large: > 2147483647
33 | - single_int32: 0O20000000000
33 | ^..................... integer is too large: > 2147483647
33 | ..................^

internal/testdata/basic.proto3test.yaml:34:19 integer is too small: < -2147483648
34 | - single_int32: -0o20000000001
34 | ^..................... integer is too small: < -2147483648
34 | ..................^

internal/testdata/basic.proto3test.yaml:37:19 integer is too large: > 2147483647
37 | - single_int32: 0B10000000000000000000000000000000
37 | ^................................. integer is too large: > 2147483647
37 | ..................^

internal/testdata/basic.proto3test.yaml:38:19 integer is too small: < -2147483648
38 | - single_int32: -0b10000000000000000000000000000001
38 | ^.................................. integer is too small: < -2147483648
38 | ..................^

internal/testdata/basic.proto3test.yaml:39:19 invalid integer: precision loss
39 | - single_int32: 1.5
39 | ^..................... invalid integer: precision loss
39 | ..................^

internal/testdata/basic.proto3test.yaml:42:19 invalid integer: precision loss
42 | - single_int32: 5.0e-1
42 | ^..................... invalid integer: precision loss
42 | ..................^

internal/testdata/basic.proto3test.yaml:48:19 integer is too large: > 9223372036854775807
48 | - single_int64: 9223372036854775808
48 | ^..................... integer is too large: > 9223372036854775807
48 | ..................^

internal/testdata/basic.proto3test.yaml:49:19 integer is too small: < -9223372036854775808
49 | - single_int64: -9223372036854775809
49 | ^..................... integer is too small: < -9223372036854775808
49 | ..................^

internal/testdata/basic.proto3test.yaml:51:19 invalid integer: precision loss
51 | - single_int64: 9007199254740992.0
51 | ^..................... invalid integer: precision loss
51 | ..................^

internal/testdata/basic.proto3test.yaml:52:19 invalid integer: strconv.ParseUint: parsing "-1": invalid syntax
52 | - single_int32: --1
52 | ^..................... invalid integer: strconv.ParseUint: parsing "-1": invalid syntax
52 | ..................^

internal/testdata/basic.proto3test.yaml:53:19 invalid integer: strconv.ParseUint: parsing "--1": invalid syntax
53 | - single_int32: ---1
53 | ^..................... invalid integer: strconv.ParseUint: parsing "--1": invalid syntax
53 | ..................^

internal/testdata/basic.proto3test.yaml:54:19 invalid integer: strconv.ParseUint: parsing "inf": invalid syntax
54 | - single_int32: inf
54 | ^..................... invalid integer: strconv.ParseUint: parsing "inf": invalid syntax
54 | ..................^

internal/testdata/basic.proto3test.yaml:55:19 invalid integer: strconv.ParseUint: parsing ".inf": invalid syntax
55 | - single_int32: .inf
55 | ^..................... invalid integer: strconv.ParseUint: parsing ".inf": invalid syntax
55 | ..................^

internal/testdata/basic.proto3test.yaml:56:19 invalid integer: strconv.ParseUint: parsing ".inf": invalid syntax
56 | - single_int32: -.inf
56 | ^..................... invalid integer: strconv.ParseUint: parsing ".inf": invalid syntax
56 | ..................^

internal/testdata/basic.proto3test.yaml:57:19 invalid integer: strconv.ParseUint: parsing ".nan": invalid syntax
57 | - single_int32: .nan
57 | ^..................... invalid integer: strconv.ParseUint: parsing ".nan": invalid syntax
57 | ..................^

internal/testdata/basic.proto3test.yaml:58:20 invalid integer: strconv.ParseUint: parsing "-1": invalid syntax
58 | - single_uint32: -1
58 | ^.................... invalid integer: strconv.ParseUint: parsing "-1": invalid syntax
58 | ...................^

internal/testdata/basic.proto3test.yaml:63:20 integer is too large: > 4294967295
63 | - single_uint32: 4294967296
63 | ^.................... integer is too large: > 4294967295
63 | ...................^

internal/testdata/basic.proto3test.yaml:65:20 invalid integer: precision loss
65 | - single_uint64: 18446744073709551616
65 | ^.................... invalid integer: precision loss
65 | ...................^

internal/testdata/basic.proto3test.yaml:71:19 invalid float: strconv.ParseFloat: parsing "1.7014118346046923e+39": value out of range
71 | - single_float: 1.7014118346046923e+39
71 | ^..................... invalid float: strconv.ParseFloat: parsing "1.7014118346046923e+39": value out of range
71 | ..................^

internal/testdata/basic.proto3test.yaml:83:20 expected scalar, got sequence
83 | - single_string: []
83 | ^.................... expected scalar, got sequence
83 | ...................^

internal/testdata/basic.proto3test.yaml:84:20 expected scalar, got mapping
84 | - single_string: {}
84 | ^.................... expected scalar, got mapping
84 | ...................^

internal/testdata/basic.proto3test.yaml:87:19 invalid base64: illegal base64 data at input byte 3
87 | - single_bytes: bad base64
87 | ^..................... invalid base64: illegal base64 data at input byte 3
87 | ..................^

internal/testdata/basic.proto3test.yaml:95:22 unknown enum value "UNKNOWN", expected one of [FOO BAR BAZ]
95 | - standalone_enum: UNKNOWN
95 | ^.................. unknown enum value "UNKNOWN", expected one of [FOO BAR BAZ]
95 | .....................^

internal/testdata/basic.proto3test.yaml:97:22 unknown enum value "foo", expected one of [FOO BAR BAZ]
97 | - standalone_enum: foo
97 | ^.................. unknown enum value "foo", expected one of [FOO BAR BAZ]
97 | .....................^

internal/testdata/basic.proto3test.yaml:98:21 expected sequence, got scalar
98 | - repeated_int32: 1
98 | ^................... expected sequence, got scalar
98 | ....................^

internal/testdata/basic.proto3test.yaml:100:30 invalid integer: strconv.ParseUint: parsing "hi": invalid syntax
100 | - repeated_int32: [1, "1", hi]
100 | ^.......... invalid integer: strconv.ParseUint: parsing "hi": invalid syntax
100 | .............................^

internal/testdata/basic.proto3test.yaml:101:21 expected sequence, got mapping
101 | - repeated_int32: {}
101 | ^................... expected sequence, got mapping
101 | ....................^

internal/testdata/basic.proto3test.yaml:102:22 expected scalar, got sequence
102 | - repeated_int32: [[]]
102 | ^.................. expected scalar, got sequence
102 | .....................^

internal/testdata/basic.proto3test.yaml:103:22 expected scalar, got sequence
103 | - repeated_int32: [[1]]
103 | ^.................. expected scalar, got sequence
103 | .....................^

internal/testdata/basic.proto3test.yaml:104:25 expected fields for bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage, got scalar
104 | - standalone_message: 1
104 | ^............... expected fields for bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage, got scalar
104 | ........................^

internal/testdata/basic.proto3test.yaml:105:25 expected fields for bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage, got sequence
105 | - standalone_message: []
105 | ^............... expected fields for bufext.cel.expr.conformance.proto3.TestAllTypes.NestedMessage, got sequence
105 | ........................^

internal/testdata/basic.proto3test.yaml:107:22 invalid duration: missing trailing 's'
107 | - single_duration: 1
107 | ^.................. invalid duration: missing trailing 's'
107 | .....................^

internal/testdata/basic.proto3test.yaml:110:22 invalid duration: too many fractional second digits
110 | - single_duration: 1.0123456789s
110 | ^.................. invalid duration: too many fractional second digits
110 | .....................^

internal/testdata/basic.proto3test.yaml:111:22 invalid duration: strconv.ParseInt: parsing "A": invalid syntax
111 | - single_duration: As
111 | ^.................. invalid duration: strconv.ParseInt: parsing "A": invalid syntax
111 | .....................^

internal/testdata/basic.proto3test.yaml:112:22 invalid duration: strconv.ParseInt: parsing "A": invalid syntax
112 | - single_duration: A.1s
112 | ^.................. invalid duration: strconv.ParseInt: parsing "A": invalid syntax
112 | .....................^

internal/testdata/basic.proto3test.yaml:113:22 invalid duration: invalid duration: too many '.' characters
113 | - single_duration: 1.1.1s
113 | ^.................. invalid duration: invalid duration: too many '.' characters
113 | .....................^

internal/testdata/basic.proto3test.yaml:114:22 invalid duration: strconv.ParseInt: parsing "B": invalid syntax
114 | - single_duration: 1.Bs
114 | ^.................. invalid duration: strconv.ParseInt: parsing "B": invalid syntax
114 | .....................^

internal/testdata/basic.proto3test.yaml:119:23 invalid timestamp: before 0001-01-01T00:00:00Z
119 | - single_timestamp: 0000-01-01T00:00:00Z
119 | ^................... invalid timestamp: before 0001-01-01T00:00:00Z
119 | ......................^

internal/testdata/basic.proto3test.yaml:121:23 invalid timestamp: parsing time "9999-12-31T23:59:60Z": second out of range
121 | - single_timestamp: 9999-12-31T23:59:60Z
121 | ^................... invalid timestamp: parsing time "9999-12-31T23:59:60Z": second out of range
121 | ......................^

internal/testdata/basic.proto3test.yaml:125:23 invalid timestamp: parsing time "10" as "2006-01-02T15:04:05.999999999Z07:00": cannot parse "10" as "2006"
125 | - single_timestamp: 10
125 | ^................. invalid timestamp: parsing time "10" as "2006-01-02T15:04:05.999999999Z07:00": cannot parse "10" as "2006"
125 | ......................^

internal/testdata/basic.proto3test.yaml:126:23 invalid timestamp: parsing time "hello" as "2006-01-02T15:04:05.999999999Z07:00": cannot parse "hello" as "2006"
126 | - single_timestamp: hello
126 | ^................. invalid timestamp: parsing time "hello" as "2006-01-02T15:04:05.999999999Z07:00": cannot parse "hello" as "2006"
126 | ......................^

internal/testdata/basic.proto3test.yaml:130:23 expected fields for google.protobuf.Timestamp, got sequence
130 | - single_timestamp: []
130 | ^................. expected fields for google.protobuf.Timestamp, got sequence
130 | ......................^

internal/testdata/basic.proto3test.yaml:135:7 unknown field "@type", expended one of [value]
135 | "@type": type.googleapis.com/google.protobuf.Int32Value
135 | ^...................................................... unknown field "@type", expended one of [value]
135 | ......^
Loading

0 comments on commit 9f10cf5

Please sign in to comment.