Skip to content

Commit e7f44e9

Browse files
betegonclaude
andcommitted
fix: address PR review — narrow catch scope, document cache assumption
1. Narrow try/catch in resolveProjectSearch to only wrap resolveFromDsn(). Previously getIssueByShortId errors (e.g. 404) were silently caught, causing a fallback to findProjectsBySlug which would duplicate the expensive short ID resolution call before failing with the same error. 2. Add comment explaining why the org_regions cache is expected to be complete when findProjectsBySlug runs: the project-search format's short suffix only comes from `sentry issue list` output, which already called listOrganizations() and populated all orgs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2c88c9c commit e7f44e9

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/commands/issue/utils.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,22 @@ async function resolveProjectSearch(
156156
// resolveFromDsn() reads from the DSN cache (populated by detectAllDsns
157157
// in tryResolveFromAlias above) + project cache. This avoids the expensive
158158
// listOrganizations() fan-out when the DSN matches the target project.
159+
// Only catch resolveFromDsn errors — getIssueByShortId errors (e.g. 404)
160+
// must propagate so we don't duplicate the expensive call via fallback.
161+
let dsnTarget: Awaited<ReturnType<typeof resolveFromDsn>> | undefined;
159162
try {
160-
const dsnTarget = await resolveFromDsn(cwd);
161-
if (
162-
dsnTarget &&
163-
dsnTarget.project.toLowerCase() === projectSlug.toLowerCase()
164-
) {
165-
const fullShortId = expandToFullShortId(suffix, dsnTarget.project);
166-
const issue = await getIssueByShortId(dsnTarget.org, fullShortId);
167-
return { org: dsnTarget.org, issue };
168-
}
163+
dsnTarget = await resolveFromDsn(cwd);
169164
} catch {
170165
// DSN resolution failed — fall through to full search
171166
}
167+
if (
168+
dsnTarget &&
169+
dsnTarget.project.toLowerCase() === projectSlug.toLowerCase()
170+
) {
171+
const fullShortId = expandToFullShortId(suffix, dsnTarget.project);
172+
const issue = await getIssueByShortId(dsnTarget.org, fullShortId);
173+
return { org: dsnTarget.org, issue };
174+
}
172175

173176
// 3. Search for project across all accessible orgs
174177
const { projects } = await findProjectsBySlug(projectSlug.toLowerCase());

src/lib/api/projects.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ export async function findProjectsBySlug(
210210

211211
// Fast path: use cached org slugs to skip the expensive listOrganizations()
212212
// round-trip (getUserRegions + listOrganizationsInRegion).
213+
// The cache is expected to be complete: callers reach this function via the
214+
// project-search format (e.g. "buybridge-5BS") whose short suffix only comes
215+
// from `sentry issue list` output — which already called listOrganizations()
216+
// and populated org_regions with all accessible orgs.
213217
const cachedOrgRegions = await getAllOrgRegions();
214218
if (cachedOrgRegions.size > 0) {
215219
const cachedSlugs = [...cachedOrgRegions.keys()];

0 commit comments

Comments
 (0)