Add contextual information to mapper errors.

This commit is contained in:
Alec Thomas
2018-07-26 17:45:12 +10:00
parent 99ff32a85f
commit 539214f23e
2 changed files with 5 additions and 5 deletions
+1 -2
View File
@@ -8,12 +8,11 @@ import (
"os"
"strings"
"golang.org/x/crypto/ssh/terminal"
"github.com/chzyer/readline"
"github.com/gliderlabs/ssh"
"github.com/google/shlex"
"github.com/kr/pty"
"golang.org/x/crypto/ssh/terminal"
"github.com/alecthomas/colour"
"github.com/alecthomas/kong"
+4 -3
View File
@@ -253,10 +253,11 @@ func (v *Value) IsBool() bool {
// Parse tokens into value, parse, and validate, but do not write to the field.
func (v *Value) Parse(scan *Scanner, target reflect.Value) error {
err := v.Mapper.Decode(&DecodeContext{Value: v, Scan: scan}, target)
if err == nil {
v.Set = true
if err != nil {
return fmt.Errorf("%s: %s", v.Summary(), err)
}
return err
v.Set = true
return nil
}
// Apply value to field.