From 4a3c19b450a66b6bb23ff000d1b883862c8411fb Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Thu, 7 Apr 2022 18:25:07 +0200 Subject: [PATCH] Fix error handling issues Signed-off-by: Kemal Akkoyun --- helpers/elf.go | 7 +++++-- libbpfgo.go | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/helpers/elf.go b/helpers/elf.go index 67e1a614..d11f373a 100644 --- a/helpers/elf.go +++ b/helpers/elf.go @@ -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. diff --git a/libbpfgo.go b/libbpfgo.go index e6310b45..8107f4b3 100644 --- a/libbpfgo.go +++ b/libbpfgo.go @@ -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 } @@ -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 } @@ -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