Skip to content

Commit 0cf1f04

Browse files
committed
tools: avoid duplicating value in validation errs
The json-schema package we're using will already prefix validation errors with the value that failed validation. This commit removes the value from the errors we produce in custom validators to avoid duplicating it in output.
1 parent c9f5ddc commit 0cf1f04

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/vectorlint/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/hex"
66
"encoding/json"
77
"encoding/pem"
8+
"errors"
89
"flag"
910
"fmt"
1011
"io/fs"
@@ -121,12 +122,12 @@ var (
121122
func validateHex(value any) error {
122123
strVal, ok := value.(string)
123124
if !ok {
124-
return fmt.Errorf("invalid non-string HexBytes value: %v", value)
125+
return errors.New("invalid non-string HexBytes value")
125126
}
126127

127128
_, err := hex.DecodeString(strVal)
128129
if err != nil {
129-
return fmt.Errorf("invalid HexBytes value: %v: %w", value, err)
130+
return fmt.Errorf("invalid HexBytes value: %w", err)
130131
}
131132

132133
return nil
@@ -135,7 +136,7 @@ func validateHex(value any) error {
135136
func validatePem(value any) error {
136137
strVal, ok := value.(string)
137138
if !ok {
138-
return fmt.Errorf("invalid non-string Pem value: %v", value)
139+
return errors.New("invalid non-string Pem value")
139140
}
140141

141142
_, rest := pem.Decode([]byte(strVal))
@@ -184,7 +185,7 @@ var curveNames = map[string]bool{
184185
func validateCurve(value any) error {
185186
strVal, ok := value.(string)
186187
if !ok {
187-
return fmt.Errorf("invalid non-string EcCurve value: %v", value)
188+
return errors.New("invalid non-string EcCurve value")
188189
}
189190

190191
if _, ok := curveNames[strVal]; !ok {

0 commit comments

Comments
 (0)