detached 6ca7ef7

fix: validate playback generator callback metadata

commit
6ca7ef7bf2863166eede621b53110e3a351d0d54
author
brice · · 2026-04-09 14:50 UTC
parent
d3f3182
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
5 files · +98 -0
M cmd/pipewiregen/internal/parser/parser.go +17 -0
@@ -71,5 +71,22 @@ func validate(m *model.Model) error {
7171 }
7272 }
7373
74+ // Validate callbacks
75+ for i, cb := range m.Callbacks {
76+ if cb.Name == "" {
77+ return fmt.Errorf("callback at index %d has empty name", i)
78+ }
79+ if cb.Signature == "" {
80+ return fmt.Errorf("callback %q has empty signature", cb.Name)
81+ }
82+ }
83+
84+ // Validate event structs
85+ for i, es := range m.EventStructs {
86+ if es.Name == "" {
87+ return fmt.Errorf("event struct at index %d has empty name", i)
88+ }
89+ }
90+
7491 return nil
7592 }
@@ -71,5 +71,22 @@ func validate(m *model.Model) error {
71 }71 }
72 }72 }
73 73
74+ // Validate callbacks
75+ for i, cb := range m.Callbacks {
76+ if cb.Name == "" {
77+ return fmt.Errorf("callback at index %d has empty name", i)
78+ }
79+ if cb.Signature == "" {
80+ return fmt.Errorf("callback %q has empty signature", cb.Name)
81+ }
82+ }
83+
84+ // Validate event structs
85+ for i, es := range m.EventStructs {
86+ if es.Name == "" {
87+ return fmt.Errorf("event struct at index %d has empty name", i)
88+ }
89+ }
90+
74 return nil91 return nil
75 }92 }
M cmd/pipewiregen/internal/parser/parser_test.go +39 -0
@@ -112,3 +112,42 @@ func TestLoadEmptySymbolSignatureReturnsError(t *testing.T) {
112112 t.Fatalf("error message should contain 'empty signature', got: %v", err)
113113 }
114114 }
115+
116+func TestLoadEmptyCallbackNameReturnsError(t *testing.T) {
117+ _, err := Load("testdata/empty_callback_name.json")
118+ if err == nil {
119+ t.Fatal("expected error for empty callback name, got nil")
120+ }
121+ if !strings.Contains(err.Error(), "validation failed") {
122+ t.Fatalf("error message should contain 'validation failed', got: %v", err)
123+ }
124+ if !strings.Contains(err.Error(), "callback") && !strings.Contains(err.Error(), "empty name") {
125+ t.Fatalf("error message should mention callback empty name, got: %v", err)
126+ }
127+}
128+
129+func TestLoadEmptyCallbackSignatureReturnsError(t *testing.T) {
130+ _, err := Load("testdata/empty_callback_signature.json")
131+ if err == nil {
132+ t.Fatal("expected error for empty callback signature, got nil")
133+ }
134+ if !strings.Contains(err.Error(), "validation failed") {
135+ t.Fatalf("error message should contain 'validation failed', got: %v", err)
136+ }
137+ if !strings.Contains(err.Error(), "callback") && !strings.Contains(err.Error(), "empty signature") {
138+ t.Fatalf("error message should mention callback empty signature, got: %v", err)
139+ }
140+}
141+
142+func TestLoadEmptyEventStructNameReturnsError(t *testing.T) {
143+ _, err := Load("testdata/empty_event_struct_name.json")
144+ if err == nil {
145+ t.Fatal("expected error for empty event struct name, got nil")
146+ }
147+ if !strings.Contains(err.Error(), "validation failed") {
148+ t.Fatalf("error message should contain 'validation failed', got: %v", err)
149+ }
150+ if !strings.Contains(err.Error(), "event struct") && !strings.Contains(err.Error(), "empty name") {
151+ t.Fatalf("error message should mention event struct empty name, got: %v", err)
152+ }
153+}
@@ -112,3 +112,42 @@ func TestLoadEmptySymbolSignatureReturnsError(t *testing.T) {
112 t.Fatalf("error message should contain 'empty signature', got: %v", err)112 t.Fatalf("error message should contain 'empty signature', got: %v", err)
113 }113 }
114 }114 }
115+
116+func TestLoadEmptyCallbackNameReturnsError(t *testing.T) {
117+ _, err := Load("testdata/empty_callback_name.json")
118+ if err == nil {
119+ t.Fatal("expected error for empty callback name, got nil")
120+ }
121+ if !strings.Contains(err.Error(), "validation failed") {
122+ t.Fatalf("error message should contain 'validation failed', got: %v", err)
123+ }
124+ if !strings.Contains(err.Error(), "callback") && !strings.Contains(err.Error(), "empty name") {
125+ t.Fatalf("error message should mention callback empty name, got: %v", err)
126+ }
127+}
128+
129+func TestLoadEmptyCallbackSignatureReturnsError(t *testing.T) {
130+ _, err := Load("testdata/empty_callback_signature.json")
131+ if err == nil {
132+ t.Fatal("expected error for empty callback signature, got nil")
133+ }
134+ if !strings.Contains(err.Error(), "validation failed") {
135+ t.Fatalf("error message should contain 'validation failed', got: %v", err)
136+ }
137+ if !strings.Contains(err.Error(), "callback") && !strings.Contains(err.Error(), "empty signature") {
138+ t.Fatalf("error message should mention callback empty signature, got: %v", err)
139+ }
140+}
141+
142+func TestLoadEmptyEventStructNameReturnsError(t *testing.T) {
143+ _, err := Load("testdata/empty_event_struct_name.json")
144+ if err == nil {
145+ t.Fatal("expected error for empty event struct name, got nil")
146+ }
147+ if !strings.Contains(err.Error(), "validation failed") {
148+ t.Fatalf("error message should contain 'validation failed', got: %v", err)
149+ }
150+ if !strings.Contains(err.Error(), "event struct") && !strings.Contains(err.Error(), "empty name") {
151+ t.Fatalf("error message should mention event struct empty name, got: %v", err)
152+ }
153+}
A cmd/pipewiregen/internal/parser/testdata/empty_callback_name.json +14 -0
@@ -0,0 +1,14 @@
1+{
2+ "libraries": [
3+ {"name": "pipewire", "soname": "libpipewire-0.3.so.0"}
4+ ],
5+ "groups": [
6+ {"name": "init", "interface": "InitAPI", "package": "out", "symbols": ["pw_init"]}
7+ ],
8+ "symbols": [
9+ {"name": "pw_init", "library": "pipewire", "group": "init", "signature": "func()"}
10+ ],
11+ "callbacks": [
12+ {"name": "", "signature": "struct{}"}
13+ ]
14+}
@@ -0,0 +1,14 @@
1+{
2+ "libraries": [
3+ {"name": "pipewire", "soname": "libpipewire-0.3.so.0"}
4+ ],
5+ "groups": [
6+ {"name": "init", "interface": "InitAPI", "package": "out", "symbols": ["pw_init"]}
7+ ],
8+ "symbols": [
9+ {"name": "pw_init", "library": "pipewire", "group": "init", "signature": "func()"}
10+ ],
11+ "callbacks": [
12+ {"name": "", "signature": "struct{}"}
13+ ]
14+}
A cmd/pipewiregen/internal/parser/testdata/empty_callback_signature.json +14 -0
@@ -0,0 +1,14 @@
1+{
2+ "libraries": [
3+ {"name": "pipewire", "soname": "libpipewire-0.3.so.0"}
4+ ],
5+ "groups": [
6+ {"name": "init", "interface": "InitAPI", "package": "out", "symbols": ["pw_init"]}
7+ ],
8+ "symbols": [
9+ {"name": "pw_init", "library": "pipewire", "group": "init", "signature": "func()"}
10+ ],
11+ "callbacks": [
12+ {"name": "pw_stream_events", "signature": ""}
13+ ]
14+}
@@ -0,0 +1,14 @@
1+{
2+ "libraries": [
3+ {"name": "pipewire", "soname": "libpipewire-0.3.so.0"}
4+ ],
5+ "groups": [
6+ {"name": "init", "interface": "InitAPI", "package": "out", "symbols": ["pw_init"]}
7+ ],
8+ "symbols": [
9+ {"name": "pw_init", "library": "pipewire", "group": "init", "signature": "func()"}
10+ ],
11+ "callbacks": [
12+ {"name": "pw_stream_events", "signature": ""}
13+ ]
14+}
A cmd/pipewiregen/internal/parser/testdata/empty_event_struct_name.json +14 -0
@@ -0,0 +1,14 @@
1+{
2+ "libraries": [
3+ {"name": "pipewire", "soname": "libpipewire-0.3.so.0"}
4+ ],
5+ "groups": [
6+ {"name": "init", "interface": "InitAPI", "package": "out", "symbols": ["pw_init"]}
7+ ],
8+ "symbols": [
9+ {"name": "pw_init", "library": "pipewire", "group": "init", "signature": "func()"}
10+ ],
11+ "event_structs": [
12+ {"name": "", "callbacks": ["process"]}
13+ ]
14+}
@@ -0,0 +1,14 @@
1+{
2+ "libraries": [
3+ {"name": "pipewire", "soname": "libpipewire-0.3.so.0"}
4+ ],
5+ "groups": [
6+ {"name": "init", "interface": "InitAPI", "package": "out", "symbols": ["pw_init"]}
7+ ],
8+ "symbols": [
9+ {"name": "pw_init", "library": "pipewire", "group": "init", "signature": "func()"}
10+ ],
11+ "event_structs": [
12+ {"name": "", "callbacks": ["process"]}
13+ ]
14+}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 8

↑↓ moveenter openesc close