Skip to content

Commit 0efafe0

Browse files
Copilotigaw
andauthored
generate-accessors: warn on unknown struct annotation qualifier
Add a named frozenset _VALID_MODES for the accepted mode qualifiers and emit a warning to stderr when parse_struct_annotation() encounters an unrecognized qualifier, then fall back gracefully to 'both'. Agent-Logs-Url: https://github.com/igaw/nvme-cli/sessions/69a3cad8-7de8-4759-9bec-63f9030907e6 Co-authored-by: igaw <1050803+igaw@users.noreply.github.com>
1 parent e6323bf commit 0efafe0

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

libnvme/tools/generator/generate-accessors.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ def parse_members(struct_name, raw_body, struct_mode, verbose):
306306
return members
307307

308308

309+
_VALID_MODES = frozenset(('both', 'none', 'readonly', 'writeonly'))
310+
311+
309312
def parse_struct_annotation(raw_body):
310313
"""Return the default mode for a struct from its generate-accessors annotation.
311314
@@ -320,6 +323,7 @@ def parse_struct_annotation(raw_body):
320323
//!generate-accessors:writeonly → 'writeonly'
321324
322325
Returns None when the annotation is absent.
326+
Prints a warning and falls back to 'both' for unrecognised qualifiers.
323327
"""
324328
first_token = raw_body.lstrip()
325329

@@ -330,7 +334,14 @@ def parse_struct_annotation(raw_body):
330334
m = re.match(pattern, first_token)
331335
if m:
332336
qualifier = m.group(1) or 'both'
333-
if qualifier not in ('none', 'readonly', 'writeonly'):
337+
if qualifier not in _VALID_MODES:
338+
print(
339+
f"warning: unknown generate-accessors qualifier "
340+
f"'{qualifier}'; valid values are: "
341+
f"{', '.join(sorted(_VALID_MODES))}. "
342+
f"Defaulting to 'both'.",
343+
file=sys.stderr,
344+
)
334345
qualifier = 'both'
335346
return qualifier
336347

0 commit comments

Comments
 (0)