Skip to content

Conversation

@aaron-ang
Copy link

What does this PR do?

Parser now distinguishes between unrecognized long args with and without values.

How did you verify your code works?

Tested the changes to ensure correct warning messages are displayed for various input scenarios.

@aaron-ang aaron-ang marked this pull request as ready for review November 23, 2025 07:15
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 23, 2025

Walkthrough

The changes modify unrecognized argument and flag handling in the streaming parser. Error messages are updated to distinguish between flags and arguments with values. The parser progression logic is simplified to always advance after emitting diagnostics. Index initialization is adjusted for short-flag handling.

Changes

Cohort / File(s) Summary
Argument Validation & Diagnostics
src/deps/zig-clap/clap/streaming.zig
Refactored unrecognized input handling in long-flag branch; updated error messages to emit "unrecognized argument: --{name}={value}" or "unrecognized flag: --{name}" instead of generic "unrecognized argument: {name}"; changed parser to always return parser.next() after diagnostics; added explicit index initialization for short-flag state creation

Pre-merge checks

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: improving unrecognized argument handling in the parser, which matches the core modification of updating error messaging and handling logic.
Description check ✅ Passed The description follows the required template with both sections completed. It explains what the PR does (distinguishing between unrecognized long args with/without values) and how it was verified (testing warning messages).

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8da6996 and 42c4ca7.

📒 Files selected for processing (1)
  • src/deps/zig-clap/clap/streaming.zig (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: cirospaciari
Repo: oven-sh/bun PR: 22946
File: test/js/sql/sql.test.ts:195-202
Timestamp: 2025-09-25T22:07:13.851Z
Learning: PR oven-sh/bun#22946: JSON/JSONB result parsing updates (e.g., returning parsed arrays instead of legacy strings) are out of scope for this PR; tests keep current expectations with a TODO. Handle parsing fixes in a separate PR.

Comment on lines 89 to 99
// unrecognized command
// if flag else arg
if (arg_info.kind == .long or arg_info.kind == .short) {
if (warn_on_unrecognized_flag) {
Output.warn("unrecognized flag: {s}{s}\n", .{ if (arg_info.kind == .long) "--" else "-", name });
Output.flush();
}

// continue parsing after unrecognized flag
return parser.next();
}

if (warn_on_unrecognized_flag) {
Output.warn("unrecognized argument: {s}\n", .{name});
if (maybe_value) |v| {
Output.warn("unrecognized argument: --{s}={s}\n", .{ name, v });
} else {
Output.warn("unrecognized flag: --{s}\n", .{name});
}
Output.flush();
}
return null;
return parser.next();
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Unrecognized long options now silently drop InvalidArgument errors

With this change, an unrecognized long argument (e.g. --q or --q=1) never raises error.InvalidArgument anymore:

  • When warn_on_unrecognized_flag is false (the default, and what test "errors" uses), the code just falls through the if and then return parser.next();, effectively skipping the unknown flag with no diagnostic.
  • This contradicts the expectations in test "errors" for --q / --q=1 and diverges from short/positional handling which still report InvalidArgument.

To keep the new, more precise warning text while preserving prior error semantics, consider gating the “warn & skip” behavior behind the flag and otherwise returning an error, e.g.:

-                    // unrecognized command
-                    if (warn_on_unrecognized_flag) {
-                        if (maybe_value) |v| {
-                            Output.warn("unrecognized argument: --{s}={s}\n", .{ name, v });
-                        } else {
-                            Output.warn("unrecognized flag: --{s}\n", .{name});
-                        }
-                        Output.flush();
-                    }
-                    return parser.next();
+                    // unrecognized command
+                    if (warn_on_unrecognized_flag) {
+                        if (maybe_value) |v| {
+                            Output.warn("unrecognized argument: --{s}={s}\n", .{ name, v });
+                        } else {
+                            Output.warn("unrecognized flag: --{s}\n", .{ name });
+                        }
+                        Output.flush();
+                        // Skip unknown flag and keep parsing further args.
+                        return parser.next();
+                    }
+                    // Preserve existing error semantics when warnings are disabled.
+                    return parser.err(arg, .{ .long = name }, error.InvalidArgument);

That keeps the improved warning messages for the Bun CLI use‑case, while ensuring the StreamingClap tests and existing callers relying on InvalidArgument continue to behave as before.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// unrecognized command
// if flag else arg
if (arg_info.kind == .long or arg_info.kind == .short) {
if (warn_on_unrecognized_flag) {
Output.warn("unrecognized flag: {s}{s}\n", .{ if (arg_info.kind == .long) "--" else "-", name });
Output.flush();
}
// continue parsing after unrecognized flag
return parser.next();
}
if (warn_on_unrecognized_flag) {
Output.warn("unrecognized argument: {s}\n", .{name});
if (maybe_value) |v| {
Output.warn("unrecognized argument: --{s}={s}\n", .{ name, v });
} else {
Output.warn("unrecognized flag: --{s}\n", .{name});
}
Output.flush();
}
return null;
return parser.next();
},
// unrecognized command
if (warn_on_unrecognized_flag) {
if (maybe_value) |v| {
Output.warn("unrecognized argument: --{s}={s}\n", .{ name, v });
} else {
Output.warn("unrecognized flag: --{s}\n", .{ name });
}
Output.flush();
// Skip unknown flag and keep parsing further args.
return parser.next();
}
// Preserve existing error semantics when warnings are disabled.
return parser.err(arg, .{ .long = name }, error.InvalidArgument);
🤖 Prompt for AI Agents
In src/deps/zig-clap/clap/streaming.zig around lines 89 to 99, unrecognized long
options currently always fall through to parser.next() and silently drop
error.InvalidArgument; change the logic so that if warn_on_unrecognized_flag is
true you keep the existing warn/flush/return parser.next() behavior, but if it
is false you return error.InvalidArgument (preserving the prior error semantics
used by tests and short/positional handling); ensure the returned
InvalidArgument includes the option name (and value variant when present)
consistent with existing error construction elsewhere in this file.

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.

1 participant