Skip to content

Commit 077bb91

Browse files
committed
fix: OrgAll should not silently switch orgs and remove non-existent command from tip
- resolveOrgAllTarget: when event is not found in the explicit org (from URL), return null instead of falling back to auto-detect. Only fall back to auto-detect on auth/network errors, where the event might exist but is unreachable. - Replace non-existent "sentry project set" in the stderr tip with env var guidance (SENTRY_ORG / SENTRY_PROJECT).
1 parent c3edd9d commit 077bb91

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/commands/event/view.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ export async function resolveOrgAllTarget(
227227
};
228228
}
229229
} catch {
230-
// Auth or network errors — fall through to auto-detect
230+
// Auth or network errors — fall through to auto-detect below
231+
return resolveOrgAndProject({ cwd, usageHint: USAGE_HINT });
231232
}
232-
return resolveOrgAndProject({ cwd, usageHint: USAGE_HINT });
233+
// Event not found in the explicit org — don't silently switch orgs
234+
return null;
233235
}
234236

235237
/**
@@ -251,7 +253,7 @@ export async function resolveAutoDetectTarget(
251253
if (resolved) {
252254
stderr.write(
253255
`Tip: Found event in ${resolved.org}/${resolved.project}. ` +
254-
`Run "sentry project set ${resolved.org}/${resolved.project}" to set as default.\n`
256+
`Set SENTRY_ORG=${resolved.org} and SENTRY_PROJECT=${resolved.project} to skip this search.\n`
255257
);
256258
return {
257259
org: resolved.org,

test/commands/event/view.test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -547,20 +547,13 @@ describe("resolveOrgAllTarget", () => {
547547
expect(result?.prefetchedEvent?.eventID).toBe("abc123");
548548
});
549549

550-
test("falls back to auto-detect when event not found", async () => {
550+
test("returns null when event not found in explicit org", async () => {
551551
resolveEventInOrgSpy.mockResolvedValue(null);
552-
resolveOrgAndProjectSpy.mockResolvedValue({
553-
org: "acme",
554-
project: "cli",
555-
orgDisplay: "acme",
556-
projectDisplay: "cli",
557-
});
558552

559553
const result = await resolveOrgAllTarget("acme", "notfound", "/tmp");
560554

561-
expect(result?.org).toBe("acme");
562-
expect(result?.project).toBe("cli");
563-
expect(resolveOrgAndProjectSpy).toHaveBeenCalled();
555+
expect(result).toBeNull();
556+
expect(resolveOrgAndProjectSpy).not.toHaveBeenCalled();
564557
});
565558

566559
test("falls back to auto-detect when resolveEventInOrg throws", async () => {
@@ -640,7 +633,7 @@ describe("resolveAutoDetectTarget", () => {
640633
expect(mockStderr.write).toHaveBeenCalledTimes(1);
641634
const hint = mockStderr.write.mock.calls[0][0] as string;
642635
expect(hint).toContain("acme/frontend");
643-
expect(hint).toContain("sentry project set");
636+
expect(hint).toContain("SENTRY_ORG=acme");
644637
});
645638

646639
test("returns null when both auto-detect and cross-project fail", async () => {

0 commit comments

Comments
 (0)