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

Fix several error handling issues #142

Merged
merged 1 commit into from Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions helpers/elf.go
Expand Up @@ -18,8 +18,11 @@ func SymbolToOffset(path, symbol string) (uint32, error) {
dynamicSymbols, dynamicSymbolsErr := f.DynamicSymbols()

// Only if we failed getting both regular and dynamic symbols - then we abort.
if regularSymbolsErr != nil && dynamicSymbolsErr != nil {
return 0, fmt.Errorf("could not open symbol sections to resolve symbol offset: %w, %w", regularSymbolsErr, dynamicSymbolsErr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go vet complains about this. Only one error should be wrapped.

if regularSymbolsErr != nil {
return 0, fmt.Errorf("could not open symbol sections to resolve symbol offset: %w", regularSymbolsErr)
}
if dynamicSymbolsErr != nil {
return 0, fmt.Errorf("could not open symbol sections to resolve symbol offset: %w", dynamicSymbolsErr)
}

// Concatenating into a single list.
Expand Down
6 changes: 3 additions & 3 deletions libbpfgo.go
Expand Up @@ -714,7 +714,7 @@ func (b *BPFMap) UpdateBatch(keys, values unsafe.Pointer, count uint32) error {
}
errC := C.bpf_map_update_batch(b.fd, keys, values, &countC, bpfMapBatchOptsToC(&opts))
if errC != 0 {
return fmt.Errorf("failed to update map %s: %w", b.name, errC)
return fmt.Errorf("failed to batch update map %s: %w", b.name, syscall.Errno(-errC))
}
return nil
}
Expand All @@ -730,7 +730,7 @@ func (b *BPFMap) DeleteKeyBatch(keys unsafe.Pointer, count uint32) error {
}
errC := C.bpf_map_delete_batch(b.fd, keys, &countC, bpfMapBatchOptsToC(opts))
if errC != 0 {
return fmt.Errorf("failed to get lookup key %d from map %s: %w", keys, b.name, syscall.Errno(-errC))
return fmt.Errorf("failed to batch delete key %d from map %s: %w", keys, b.name, syscall.Errno(-errC))
}
return nil
}
Expand Down Expand Up @@ -869,7 +869,7 @@ func (p *BPFProg) Unpin(path string) error {
errC := C.bpf_program__unpin(p.prog, cs)
C.free(unsafe.Pointer(cs))
if errC != 0 {
return fmt.Errorf("failed to unpin program %s to %s: %w", p.name, path, errC)
return fmt.Errorf("failed to unpin program %s to %s: %w", p.name, path, syscall.Errno(-errC))
}
p.pinnedPath = ""
return nil
Expand Down