Skip to content

bpf2go: improve duplicate type name error message#1993

Merged
ti-mo merged 1 commit into
cilium:mainfrom
wucm667:fix/bpf2go-duplicate-type-error
May 13, 2026
Merged

bpf2go: improve duplicate type name error message#1993
ti-mo merged 1 commit into
cilium:mainfrom
wucm667:fix/bpf2go-duplicate-type-error

Conversation

@wucm667
Copy link
Copy Markdown
Contributor

@wucm667 wucm667 commented Apr 29, 2026

When --type T is used for a type that is already exported via a
variable or map k/v, bpf2go reports a confusing error about the
type name being used multiple times.

Update the error message to guide users toward the fix:
remove the redundant --type flag.

Fixes #1638

@wucm667 wucm667 requested a review from a team as a code owner April 29, 2026 00:09
@wucm667 wucm667 force-pushed the fix/bpf2go-duplicate-type-error branch from 58692e7 to fc5f6c4 Compare April 29, 2026 00:10
@ti-mo
Copy link
Copy Markdown
Contributor

ti-mo commented May 7, 2026

@wucm667 Thanks for the patch, but I don't really agree that the behaviour should be changed. Maybe the error message is a little obtuse at the moment, that could likely be improved.

If there's already a variable or map k/v of type T, specifying it additionally using --type T will effectively make that flag dead code. It's also not ideal to couple the contents of go:generate statements to type names contained in C files. Including more than a handful of types using CLI flags sounds really cumbersome, especially when the list of types changes frequently.

For example, in Cilium we use this for exporting enums to Go using a bpf2go-like tool:

#define EXPORT_TYPE(type) __expand_type(type, __COUNTER__)
#define __expand_type(type, n) ___expand_type(type, n)
#define ___expand_type(type, n) type __dpexp_ ## n

...
enum identity {
       UNKNOWN_ID = 0,
       HOST_ID = 1,
       WORLD_ID = 2,
};
EXPORT_TYPE(enum identity);

I'd probably just update the error string in sortTypes to read something like "type name %q is used multiple times (remove its --type flag?)".

@wucm667
Copy link
Copy Markdown
Contributor Author

wucm667 commented May 7, 2026

@ti-mo Good point — makes sense. Updated to just improve the error message as you suggested. The --type flag is indeed dead code in this case, so guiding the user to remove it is the right approach.

@ti-mo ti-mo force-pushed the fix/bpf2go-duplicate-type-error branch from a29d1de to ae397d6 Compare May 13, 2026 13:18
When --type T is used for a type that is already exported via a
variable or map k/v, bpf2go reports a confusing error about the
type name being used multiple times.

Update the error message to guide users toward the fix:
remove the redundant --type flag.

Fixes cilium#1638

Signed-off-by: wucm667 <stevenwucongmin@gmail.com>
@ti-mo ti-mo force-pushed the fix/bpf2go-duplicate-type-error branch from ae397d6 to a3d10db Compare May 13, 2026 13:18
@ti-mo ti-mo changed the title fix(bpf2go): deduplicate types by name to avoid false duplicate error bpf2go: improve duplicate type name error message May 13, 2026
@ti-mo ti-mo merged commit 545bc1c into cilium:main May 13, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bpf2go: bogus "type name is used multiple times" error

2 participants