Skip to content

Commit

Permalink
parse: provide more context for parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
gobwas committed Sep 5, 2020
1 parent f273679 commit 6cb37cc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion parse/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (p *Parser) isBoolFlag(name string) bool {
}

func (p *Parser) fail(f string, args ...interface{}) {
p.err = fmt.Errorf(f, args...)
p.err = fmt.Errorf("args: %s", fmt.Sprintf(f, args...))
}

func split(s string, sep byte) (a, b string, ok bool) {
Expand Down
8 changes: 4 additions & 4 deletions parse/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Lookup interface {

// ErrNoFile is an returned by Lookup implementation to report that lookup
// didn't find any file to parse.
var ErrNoFile = fmt.Errorf("flagutil/file: no file")
var ErrNoFile = fmt.Errorf("file: no file")

// LookupFunc is an adapter that allows the use of ordinar functions as Lookup.
type LookupFunc func() (io.ReadCloser, error)
Expand Down Expand Up @@ -95,7 +95,7 @@ func (p PathLookup) Lookup() (io.ReadCloser, error) {
}
if info.IsDir() {
return nil, fmt.Errorf(
"flagutil/file: can't parse %s since its dir",
"file: can't parse %s since its dir",
p,
)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func (p *Parser) Parse(_ context.Context, fs parse.FlagSet) error {
bts, err := p.readSource()
if err == ErrNoFile {
if p.Required {
err = fmt.Errorf("flagutil/file: source not found")
err = fmt.Errorf("file: source not found")
} else {
err = nil
}
Expand All @@ -141,7 +141,7 @@ func (p *Parser) Parse(_ context.Context, fs parse.FlagSet) error {
}
x, err := p.Syntax.Unmarshal(bts)
if err != nil {
return fmt.Errorf("flagutil/file: syntax error: %v", err)
return fmt.Errorf("file: syntax error: %v", err)
}
return parse.Setup(x, parse.VisitorFunc{
SetFunc: func(name, value string) error {
Expand Down
2 changes: 1 addition & 1 deletion parse/pargs/posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (p *Parser) shorthands(fs parse.FlagSet) map[string]string {
}

func (p *Parser) fail(f string, args ...interface{}) {
p.err = fmt.Errorf(f, args...)
p.err = fmt.Errorf("pargs: %s", fmt.Sprintf(f, args...))
}

func split(s string, sep byte) (a, b string, ok bool) {
Expand Down

0 comments on commit 6cb37cc

Please sign in to comment.