use errors.Is() to check for errors (#1730)
Since go 1.13 you can wrap errors. This make it no longer possible to compare with `==`, instead you have to compare with `errors.Is()`. I noticed this problem because -h was no longer working after I stared wrapping the errors in my custom FlagErrorFunc function. Note that this is only a problem when a custom help flag is defined. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -18,6 +18,7 @@ package cobra
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -990,7 +991,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||
if err != nil {
|
||||
// Always show help if requested, even if SilenceErrors is in
|
||||
// effect
|
||||
if err == flag.ErrHelp {
|
||||
if errors.Is(err, flag.ErrHelp) {
|
||||
cmd.HelpFunc()(cmd, args)
|
||||
return cmd, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user