Skip to content

Commit

Permalink
Merge pull request #86 from jack-w-shaw/revert_to_WriteError
Browse files Browse the repository at this point in the history
Revert to WriteError
  • Loading branch information
jack-w-shaw authored Jan 9, 2023
2 parents 790481d + 7ba9989 commit b65277e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func handleCommandError(c Command, ctx *Context, err error, f *gnuflag.FlagSet)
case ErrSilent:
return 2, true
default:
ctx.Errorf("%s", err)
WriteError(ctx.Stderr, err)
return 2, true
}
}
Expand Down Expand Up @@ -421,7 +421,7 @@ func Main(c Command, ctx *Context, args []string) int {
return err.(*RcPassthroughError).Code
}
if err != ErrSilent {
ctx.Errorf("%s", err)
WriteError(ctx.Stderr, err)
}
return 1
}
Expand Down
2 changes: 1 addition & 1 deletion cmdtesting/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func RunCommandInDir(c *gc.C, com cmd.Command, args []string, dir string) (*cmd.

func runCommand(ctx *cmd.Context, com cmd.Command, args []string) (*cmd.Context, error) {
if err := InitCommand(com, args); err != nil {
ctx.Errorf("%s", err)
cmd.WriteError(ctx.Stderr, err)
return ctx, err
}
return ctx, com.Run(ctx)
Expand Down
2 changes: 1 addition & 1 deletion supercommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func (c *SuperCommand) Run(ctx *Context) error {
return handleErr
}

ctx.Errorf("%s", err)
WriteError(ctx.Stderr, err)
logger.Debugf("error stack: \n%v", errors.ErrorStack(err))

// Err has been logged above, we can make the err silent so it does not log again in cmd/main
Expand Down
2 changes: 1 addition & 1 deletion supercommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (s *SuperCommandSuite) TestLogging(c *gc.C) {
sc.Register(&TestCommand{Name: "blah"})
code := cmd.Main(sc, s.ctx, []string{"blah", "--option", "error", "--debug"})
c.Assert(code, gc.Equals, 1)
c.Assert(cmdtesting.Stderr(s.ctx), gc.Matches, `(?m).* ERROR .* BAM!\n.* DEBUG .* error stack: \n.*`)
c.Assert(cmdtesting.Stderr(s.ctx), gc.Matches, `(?m)ERROR BAM!\n.* DEBUG .* error stack: \n.*`)
}

type notifyTest struct {
Expand Down

0 comments on commit b65277e

Please sign in to comment.