Skip to content

Commit

Permalink
better error handling of start/fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
brycekahle committed May 8, 2024
1 parent 316fe3d commit 67f84ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions kprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func (p *Probe) attachKprobe() error {
startFunc, fallbackFunc = eventsFunc, pmuFunc
}

var err error
var startErr, fallbackErr error
var tl *tracefsLink
if tl, err = startFunc(); err != nil {
if tl, err = fallbackFunc(); err != nil {
return err
if tl, startErr = startFunc(); startErr != nil {
if tl, fallbackErr = fallbackFunc(); fallbackErr != nil {
return errors.Join(startErr, fallbackErr)
}
}

Expand Down
9 changes: 5 additions & 4 deletions uprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package manager

import (
"debug/elf"
"errors"
"fmt"
"regexp"
)
Expand Down Expand Up @@ -142,11 +143,11 @@ func (p *Probe) attachUprobe() error {
startFunc, fallbackFunc = eventsFunc, pmuFunc
}

var err error
var startErr, fallbackErr error
var tl *tracefsLink
if tl, err = startFunc(); err != nil {
if tl, err = fallbackFunc(); err != nil {
return err
if tl, startErr = startFunc(); startErr != nil {
if tl, fallbackErr = fallbackFunc(); fallbackErr != nil {
return errors.Join(startErr, fallbackErr)
}
}

Expand Down

0 comments on commit 67f84ef

Please sign in to comment.