Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscalls: do not conceal BPF_PROG_* syscall errors #334

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions syscalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,9 @@ func wrapObjError(err error) error {
return nil
}
if errors.Is(err, unix.ENOENT) {
return fmt.Errorf("%w", ErrNotExist)
cyphar marked this conversation as resolved.
Show resolved Hide resolved
err = ErrNotExist
}

return errors.New(err.Error())
return fmt.Errorf("%w", err)
}

func wrapMapError(err error) error {
Expand Down
18 changes: 18 additions & 0 deletions syscalls_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ebpf

import (
"errors"
"strings"
"testing"

"github.com/cilium/ebpf/internal/testutils"
"golang.org/x/sys/unix"
)

func TestObjNameCharacters(t *testing.T) {
Expand All @@ -23,6 +25,22 @@ func TestObjNameCharacters(t *testing.T) {
}
}

func TestWrapObjError(t *testing.T) {
customError := errors.New("custom error for test")
for inErr, outErr := range map[error]error{
unix.ENOENT: ErrNotExist,
unix.EPERM: unix.EPERM,
unix.EACCES: unix.EACCES,
unix.ENOANO: unix.ENOANO, // dummy error -- never actually returned
customError: customError,
} {
gotErr := wrapObjError(inErr)
if !errors.Is(gotErr, outErr) {
t.Errorf("wrapObjError(%v) doesn't wrap %v: got %v", inErr, outErr, gotErr)
}
}
}

func TestHaveBatchAPI(t *testing.T) {
testutils.CheckFeatureTest(t, haveBatchAPI)
}
Expand Down