It seems that all error messages, which are returned by a Run() method of a command struct, are prefixed with the call chain of the program.
Consider the following sample program:
package main
import (
"errors"
"fmt"
"github.com/alecthomas/kong"
)
type Context struct {}
type Cmd struct {}
func (c *Cmd) Run(ctx *Context) error {
return errors.New("Command failed.")
}
var cli struct {
Cmd Cmd `cmd:"" default:"1"`
}
func main() {
ctx := kong.Parse(&cli)
err := ctx.Run(&Context{})
if err != nil {
fmt.Println(err)
}
}
In my application, the error messages returned by Run() are end-user facing, so the “call-chain” prefix wouldn’t mean anything to my users and might potentially confuse them.
Would it be possible to drop the prefixing, and just pass on the original error object as is? I.e., without wrapping, modifying, or re-serializing the error object at all?
It seems that the new behaviour was introduced in #344, where callbacks.go now re-serializes the original error message, in order to add the prefix info:
|
return fmt.Errorf("%s.%s(): %w", v.Type(), name, err) |
It seems that all error messages, which are returned by a
Run()method of a command struct, are prefixed with the call chain of the program.Consider the following sample program:
Command failed.main.Cmd.Run(): Command failed.In my application, the error messages returned by
Run()are end-user facing, so the “call-chain” prefix wouldn’t mean anything to my users and might potentially confuse them.Would it be possible to drop the prefixing, and just pass on the original error object as is? I.e., without wrapping, modifying, or re-serializing the error object at all?
It seems that the new behaviour was introduced in #344, where
callbacks.gonow re-serializes the original error message, in order to add the prefix info:kong/callbacks.go
Line 134 in 1b4d0d7