diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-13 09:59:39 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-13 09:59:39 +0300 |
| commit | 460e1ba7a7228aa324a2f36b8693951b19866c62 (patch) | |
| tree | f910695f3be0133bf325ebbc7f9448f1cf7f9c9f | |
| parent | 7dd508503595b023de03d78de487b4f52c7a98f0 (diff) | |
fix: wrap SetMaxEntries and GetMap errors in resizeBPFMap with map name context
Raw errors from GetMap and SetMaxEntries gave no indication of which BPF
map failed. Wrap both with fmt.Errorf including the map name (and target
size for SetMaxEntries) so callers can immediately identify the offending
map. Also simplify resizeBPFMaps to return directly since resizeBPFMap
now carries full context, removing the redundant outer wrap.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rw-r--r-- | internal/bpfsetup.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/internal/bpfsetup.go b/internal/bpfsetup.go index f8f2c60..f8347bf 100644 --- a/internal/bpfsetup.go +++ b/internal/bpfsetup.go @@ -24,22 +24,24 @@ func setBPFGlobals(cfg flags.Config, bpfModule *bpf.Module) error { } func resizeBPFMaps(cfg flags.Config, bpfModule *bpf.Module) error { - if err := resizeBPFMap(bpfModule, "event_map", uint32(cfg.EventMapSize)); err != nil { - return fmt.Errorf("event_map: %w", err) - } - return nil + // resizeBPFMap already includes the map name in any error it returns, + // so no additional wrapping is needed here. + return resizeBPFMap(bpfModule, "event_map", uint32(cfg.EventMapSize)) } func resizeBPFMap(module *bpf.Module, name string, size uint32) error { m, err := module.GetMap(name) if err != nil { - return err + // Wrap with map name so callers know which map lookup failed. + return fmt.Errorf("resize map %s: get map: %w", name, err) } if err = m.SetMaxEntries(size); err != nil { - return err + // Wrap with map name and target size so callers know which map failed + // and what size was requested. + return fmt.Errorf("resize map %s to %d: %w", name, size, err) } if actual := m.MaxEntries(); actual != size { - return fmt.Errorf("map resize to %d failed, expected %v, actual %v", size, size, actual) + return fmt.Errorf("resize map %s to %d failed: actual size is %d", name, size, actual) } return nil } |
