Skip to content

Commit

Permalink
fix defer func statements order in workerS.parse()
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Oct 22, 2024
1 parent 6a6b8f2 commit e40e29b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions cli/for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ func (*workerS) Version() string { return "v0
func (*workerS) Root() *RootCommand { return nil }
func (*workerS) Args() []string { return nil } //
func (w *workerS) SuggestRetCode() int { return w.retCode } //
func (w *workerS) ParsedState() ParsedState { return nil }

//

Expand Down
12 changes: 6 additions & 6 deletions cli/worker/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ func (w *workerS) parse(ctx context.Context, pc *parseCtx) (err error) { //nolin
ec := errorsv3.New("tasks failed")

defer func() {
ec.Defer(&err)

if err == nil {
w.parsingCtx = pc // save pc for later, OnAction might need it.
}

if len(w.tasksAfterParse) > 0 {
for _, task := range w.tasksAfterParse {
if task != nil {
ec.Attach(task(w, pc, err))
}
}
}

ec.Defer(&err)

if err == nil {
w.parsingCtx = pc // save pc for later, OnAction might need it.
}
}()

logz.VerboseContext(ctx, "parsing command line args ...", "args", w.args)
Expand Down

0 comments on commit e40e29b

Please sign in to comment.