Skip to content

Commit 94a5260

Browse files
betegonclaude
andcommitted
fix(auth): move auth guard inside try block and fix buildListCommand type
Move the auth check inside the try block so maybeRecoverWithHelp can intercept AuthError when "help" is a positional arg. Previously the guard fired before the try, so `sentry issue list help` while unauthenticated would trigger a login prompt instead of showing the command help. Also add `auth?: boolean` to buildListCommand's builderArgs type. The spread to buildCommand already passed it through at runtime — the type just wasn't reflecting it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1d858c8 commit 94a5260

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/lib/command.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,19 @@ export function buildCommand<
570570
throw err;
571571
};
572572

573-
if (requiresAuth && !isAuthenticated()) {
574-
throw new AuthError("not_authenticated");
575-
}
576-
577573
// Iterate the generator using manual .next() instead of for-await-of
578574
// so we can capture the return value (done: true result). The return
579575
// value carries the final `hint` — for-await-of discards it.
576+
//
577+
// Auth guard is inside the try block so that maybeRecoverWithHelp can
578+
// intercept the AuthError when "help" appears as a positional arg (e.g.
579+
// `sentry issue list help`). Without this, the auth prompt would fire
580+
// before the help-recovery path could show the command's help text.
580581
try {
582+
if (requiresAuth && !isAuthenticated()) {
583+
throw new AuthError("not_authenticated");
584+
}
585+
581586
const generator = originalFunc.call(
582587
this,
583588
cleanFlags as FLAGS,

src/lib/list-command.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ export function buildListCommand<
464464
readonly func: ListCommandFunction<FLAGS, ARGS, CONTEXT>;
465465
// biome-ignore lint/suspicious/noExplicitAny: OutputConfig is generic but type is erased at the builder level
466466
readonly output?: OutputConfig<any>;
467+
readonly auth?: boolean;
467468
},
468469
options?: ListCommandOptions
469470
): Command<CONTEXT> {

0 commit comments

Comments
 (0)