Skip to content
This repository was archived by the owner on Oct 23, 2026. It is now read-only.

Commit 5d90116

Browse files
fix: preserve org scope through fuzzy recovery and resolve DSN-style org IDs
- Pass scopedOrg through handleProjectNotFound to fuzzy recovery calls in both project/list.ts and org-list.ts - Remove isDisplayName guard from scopedOrg filter so org scoping applies to slug-based recovery lookups too - Call resolveEffectiveOrg for project-search mode when org is set, handling DSN-style identifiers (e.g. o1081365 → my-org) - Improve error messages when specified org is inaccessible to distinguish from the generic 'any accessible organization' message - Extract resolveOrgInParsed helper to keep dispatchOrgScopedList within cognitive complexity budget
1 parent 0bf3b84 commit 5d90116

3 files changed

Lines changed: 85 additions & 39 deletions

File tree

‎src/commands/project/list.ts‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,13 @@ async function handleProjectNotFound(
533533
projectSlug: string,
534534
orgs: { slug: string }[],
535535
flags: ListFlags,
536-
options?: { originalSlug?: string; isRecoveryAttempt?: boolean }
536+
options?: {
537+
originalSlug?: string;
538+
isRecoveryAttempt?: boolean;
539+
scopedOrg?: string;
540+
}
537541
): Promise<ListResult<ProjectWithOrg>> {
538-
const { originalSlug, isRecoveryAttempt = false } = options ?? {};
542+
const { originalSlug, isRecoveryAttempt = false, scopedOrg } = options ?? {};
539543
const displaySlug = originalSlug ?? projectSlug;
540544

541545
// Skip triage on recovery attempts to prevent infinite recursion.
@@ -563,23 +567,29 @@ async function handleProjectNotFound(
563567

564568
if (outcome.kind === "fuzzy-match") {
565569
// Pass isRecoveryAttempt=true to prevent infinite recursion if the
566-
// fuzzy-recovered slug also fails to resolve.
570+
// fuzzy-recovered slug also fails to resolve. Preserve scopedOrg so
571+
// the recovery lookup stays scoped to the user's specified org.
567572
return handleProjectSearch(outcome.project, flags, {
568573
isRecoveryAttempt: true,
574+
scopedOrg,
569575
});
570576
}
571577

572578
// JSON mode returns empty array; human mode throws a helpful error
573579
if (flags.json) {
574580
return { items: [] };
575581
}
582+
const fallback = scopedOrg
583+
? [
584+
`No project with this name found in organization '${scopedOrg}'`,
585+
`Check the organization slug or try: sentry project list ${scopedOrg}/`,
586+
]
587+
: ["No project with this slug found in any accessible organization"];
576588
throw new ResolutionError(
577589
`Project '${displaySlug}'`,
578590
"not found",
579591
`sentry project list <org>/${projectSlug}`,
580-
outcome.suggestions.length > 0
581-
? outcome.suggestions
582-
: ["No project with this slug found in any accessible organization"]
592+
outcome.suggestions.length > 0 ? outcome.suggestions : fallback
583593
);
584594
}
585595

@@ -610,9 +620,10 @@ export async function handleProjectSearch(
610620
);
611621

612622
// When the caller provided an org (e.g. "org/My Project"), scope the
613-
// search to that org instead of all accessible orgs.
623+
// search to that org instead of all accessible orgs. This applies to both
624+
// display-name searches and slug-based recovery lookups.
614625
const orgs =
615-
isDisplayName && scopedOrg !== undefined
626+
scopedOrg !== undefined
616627
? foundOrgs.filter((o) => o.slug === scopedOrg)
617628
: foundOrgs;
618629

@@ -629,6 +640,7 @@ export async function handleProjectSearch(
629640
return handleProjectNotFound(projectSlug, orgs, flags, {
630641
originalSlug,
631642
isRecoveryAttempt,
643+
scopedOrg,
632644
});
633645
}
634646

‎src/lib/org-list.ts‎

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,10 @@ export async function handleProjectSearch<TEntity, TWithOrg>(
796796
);
797797

798798
// When the caller provided an org (e.g. "org/My Project"), scope the
799-
// search to that org instead of all accessible orgs.
799+
// search to that org instead of all accessible orgs. This applies to both
800+
// display-name searches and slug-based recovery lookups.
800801
const orgs =
801-
isDisplayName && scopedOrg !== undefined
802+
scopedOrg !== undefined
802803
? foundOrgs.filter((o) => o.slug === scopedOrg)
803804
: foundOrgs;
804805

@@ -842,13 +843,17 @@ export async function handleProjectSearch<TEntity, TWithOrg>(
842843
return { items: [] };
843844
}
844845

846+
const fallback = scopedOrg
847+
? [
848+
`No project with this name found in organization '${scopedOrg}'`,
849+
`Check the organization slug or try: sentry project list ${scopedOrg}/`,
850+
]
851+
: ["No project with this slug found in any accessible organization"];
845852
throw new ResolutionError(
846853
`Project '${displaySlug}'`,
847854
"not found",
848855
`${config.commandPrefix} <org>/${projectSlug}`,
849-
outcome.suggestions.length > 0
850-
? outcome.suggestions
851-
: ["No project with this slug found in any accessible organization"]
856+
outcome.suggestions.length > 0 ? outcome.suggestions : fallback
852857
);
853858
}
854859

@@ -1062,6 +1067,28 @@ async function resolveOrgSlugMatch(
10621067
return { type: "org-all", org: matchingOrg.slug };
10631068
}
10641069

1070+
/**
1071+
* Resolve DSN-style org identifiers and set org/project context for modes
1072+
* that carry an org field. Returns the (possibly updated) parsed object.
1073+
*/
1074+
async function resolveOrgInParsed(
1075+
parsed: ParsedOrgProject
1076+
): Promise<ParsedOrgProject> {
1077+
if (!("org" in parsed && parsed.org)) {
1078+
return parsed;
1079+
}
1080+
const effectiveOrg = await resolveEffectiveOrg(parsed.org);
1081+
const resolved =
1082+
effectiveOrg !== parsed.org ? { ...parsed, org: effectiveOrg } : parsed;
1083+
if (resolved.type === "explicit" || resolved.type === "org-all") {
1084+
setOrgProjectContext(
1085+
[effectiveOrg],
1086+
resolved.type === "explicit" ? [resolved.project] : []
1087+
);
1088+
}
1089+
return resolved;
1090+
}
1091+
10651092
/**
10661093
* Validate the cursor flag and dispatch to the correct mode handler.
10671094
*
@@ -1111,19 +1138,7 @@ export async function dispatchOrgScopedList<TEntity, TWithOrg>(
11111138
);
11121139
}
11131140

1114-
if (
1115-
effectiveParsed.type === "explicit" ||
1116-
effectiveParsed.type === "org-all"
1117-
) {
1118-
const effectiveOrg = await resolveEffectiveOrg(effectiveParsed.org);
1119-
if (effectiveOrg !== effectiveParsed.org) {
1120-
effectiveParsed = { ...effectiveParsed, org: effectiveOrg };
1121-
}
1122-
setOrgProjectContext(
1123-
[effectiveOrg],
1124-
effectiveParsed.type === "explicit" ? [effectiveParsed.project] : []
1125-
);
1126-
}
1141+
effectiveParsed = await resolveOrgInParsed(effectiveParsed);
11271142

11281143
const defaults = buildDefaultHandlers(config);
11291144
const handlers: ModeHandlerMap = { ...defaults, ...overrides };

‎src/lib/resolve-target.ts‎

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,15 +1640,22 @@ export async function resolveOrgProjectTarget(
16401640
case "project-search": {
16411641
const displaySlug = parsed.originalSlug ?? parsed.projectSlug;
16421642
const isDisplayName = parsed.originalSlug !== undefined;
1643+
1644+
// Resolve DSN-style org identifiers (e.g. "o1081365" → "my-org")
1645+
// before using the org for filtering.
1646+
const scopedOrg = parsed.org
1647+
? await resolveEffectiveOrg(parsed.org)
1648+
: undefined;
1649+
16431650
const { projects, orgs: foundOrgs } = isDisplayName
16441651
? { projects: [], orgs: await listOrganizations() }
16451652
: await findProjectsBySlug(parsed.projectSlug);
16461653

16471654
// When the caller provided an org (e.g. "org/My Project"), scope the
1648-
// display-name search to that org instead of all accessible orgs.
1655+
// search to that org instead of all accessible orgs.
16491656
const orgs =
1650-
isDisplayName && parsed.org !== undefined
1651-
? foundOrgs.filter((o) => o.slug === parsed.org)
1657+
scopedOrg !== undefined
1658+
? foundOrgs.filter((o) => o.slug === scopedOrg)
16521659
: foundOrgs;
16531660

16541661
if (projects.length === 0) {
@@ -1674,13 +1681,17 @@ export async function resolveOrgProjectTarget(
16741681
});
16751682
}
16761683

1684+
const fallback = scopedOrg
1685+
? [
1686+
`No project with this name found in organization '${scopedOrg}'`,
1687+
`Check the organization slug or try: sentry project list ${scopedOrg}/`,
1688+
]
1689+
: ["No project with this slug found in any accessible organization"];
16771690
throw new ResolutionError(
16781691
`Project '${displaySlug}'`,
16791692
"not found",
16801693
`sentry ${commandName} <org>/${parsed.projectSlug}`,
1681-
outcome.suggestions.length > 0
1682-
? outcome.suggestions
1683-
: ["No project with this slug found in any accessible organization"]
1694+
outcome.suggestions.length > 0 ? outcome.suggestions : fallback
16841695
);
16851696
}
16861697

@@ -1883,15 +1894,21 @@ export async function resolveTargetsFromParsedArg(
18831894
// When the input is a display name (originalSlug set, contains spaces),
18841895
// skip the slug-based API lookup and go straight to fuzzy matching.
18851896
const isDisplayName = parsed.originalSlug !== undefined;
1897+
1898+
// Resolve DSN-style org identifiers before filtering.
1899+
const scopedOrg = parsed.org
1900+
? await resolveEffectiveOrg(parsed.org)
1901+
: undefined;
1902+
18861903
const { projects: matches, orgs: foundOrgs } = isDisplayName
18871904
? { projects: [], orgs: await listOrganizations() }
18881905
: await findProjectsBySlug(parsed.projectSlug);
18891906

18901907
// When the caller provided an org (e.g. "org/My Project"), scope the
18911908
// search to that org instead of all accessible orgs.
18921909
const orgs =
1893-
isDisplayName && parsed.org !== undefined
1894-
? foundOrgs.filter((o) => o.slug === parsed.org)
1910+
scopedOrg !== undefined
1911+
? foundOrgs.filter((o) => o.slug === scopedOrg)
18951912
: foundOrgs;
18961913

18971914
if (matches.length === 0) {
@@ -1929,12 +1946,14 @@ export async function resolveTargetsFromParsedArg(
19291946
return { targets };
19301947
}
19311948

1949+
const fallback = scopedOrg
1950+
? [
1951+
`No project with this name found in organization '${scopedOrg}'`,
1952+
`Check the organization slug or try: sentry project list ${scopedOrg}/`,
1953+
]
1954+
: ["No project with this slug found in any accessible organization"];
19321955
const suggestions =
1933-
outcome.suggestions.length > 0
1934-
? outcome.suggestions
1935-
: [
1936-
"No project with this slug found in any accessible organization",
1937-
];
1956+
outcome.suggestions.length > 0 ? outcome.suggestions : fallback;
19381957
throw new ResolutionError(
19391958
`Project '${displaySlug}'`,
19401959
"not found",

0 commit comments

Comments
 (0)