@@ -12,6 +12,11 @@ import (
1212/* This file contains all the logic to parse a data structure
1313 using reflection tags from a map of keys and values. */
1414
15+ var (
16+ ErrUnsupported = fmt .Errorf ("unsupported type, please report this if this type should be supported" )
17+ ErrInvalidByte = fmt .Errorf ("invalid byte" )
18+ )
19+
1520// Struct does most of the heavy lifting. Called every time a struct is encountered.
1621// The entire process begins here. It's very recursive.
1722func (p * parser ) Struct (field reflect.Value , prefix string ) (bool , error ) {
@@ -154,18 +159,17 @@ func (p *parser) Member(field reflect.Value, tag, envval string) (bool, error) {
154159 val , err = strconv .ParseBool (envval )
155160 field .SetBool (val )
156161 case typeError : // lul
157- field .Set (reflect .ValueOf (fmt .Errorf (envval )))
162+ field .Set (reflect .ValueOf (fmt .Errorf (envval ))) // nolint: goerr113
158163 default :
159164 var ok bool
160165
161166 if ok , err = p .Interface (field , tag , envval ); err == nil && ! ok {
162- err = fmt .Errorf ("unsupported type: %v (val: %s) - please report this if " +
163- "this type should be supported" , field .Type (), envval )
167+ err = fmt .Errorf ("%w: %v (val: %s)" , ErrUnsupported , field .Type (), envval )
164168 }
165169 }
166170
167171 if err != nil {
168- return false , fmt .Errorf ("%s: %v " , tag , err )
172+ return false , fmt .Errorf ("%s: %w " , tag , err )
169173 }
170174
171175 return true , nil
@@ -295,7 +299,7 @@ func parseUint(field reflect.Value, intType, envval string) error {
295299 field .Set (reflect .ValueOf (envval [0 ]))
296300 return nil
297301 default :
298- return fmt .Errorf ("invalid byte : %s" , envval )
302+ return fmt .Errorf ("%w : %s" , ErrInvalidByte , envval )
299303 }
300304 case typeUINT16 :
301305 val , err = strconv .ParseUint (envval , 10 , 16 )
@@ -307,9 +311,10 @@ func parseUint(field reflect.Value, intType, envval string) error {
307311
308312 if err == nil {
309313 field .SetUint (val )
314+ return nil
310315 }
311316
312- return err
317+ return fmt . Errorf ( "integer parse error: %w" , err )
313318}
314319
315320func parseInt (intType , envval string ) (int64 , error ) {
0 commit comments