Skip to content

Commit

Permalink
Fix error handling issues (#142)
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
  • Loading branch information
kakkoyun committed Apr 7, 2022
1 parent 5ced2a6 commit 222eac7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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)
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

0 comments on commit 222eac7

Please sign in to comment.