Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/lib/error-reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*
* Provides two things:
*
* 1. **Silencing rules** — `OutputError`, expected-state `AuthError`, and
* 401–499 `ApiError` are not sent to Sentry as issues. A
* `cli.error.silenced` metric preserves volume + user/org context.
* 1. **Silencing rules** — `OutputError`, `ResolutionError`, expected-state
* `AuthError`, and 401–499 `ApiError` are not sent to Sentry as issues.
* A `cli.error.silenced` metric preserves volume + user/org context.
*
* 2. **Grouping tags** — enriches every error event with `cli_error.*` tags
* that Sentry's server-side fingerprint rules use for stable grouping.
Expand Down Expand Up @@ -42,7 +42,11 @@
* Reasons an error may be silenced (not sent to Sentry as an issue).
* Exposed as the `reason` attribute on the `cli.error.silenced` metric.
*/
type SilenceReason = "output_error" | "auth_expected" | "api_user_error";
type SilenceReason =
| "output_error"
| "auth_expected"
| "api_user_error"
| "user_input_error";

/**
* Classify whether an error should be silenced.
Expand All @@ -54,6 +58,9 @@
if (error instanceof OutputError) {
return "output_error";
}
if (error instanceof ResolutionError) {
return "user_input_error";
}

Check warning on line 63 in src/lib/error-reporting.ts

View check run for this annotation

@sentry/warden / warden: find-bugs

ResolutionError silences server-side (5xx/network) failures, not just user-input errors

Silencing all `ResolutionError` instances will suppress Sentry reports for genuine server errors (e.g. 5xx responses, network failures) that are wrapped as `ResolutionError` in several resolvers — add a distinguishing property or only silence specific sub-types/headlines to avoid hiding real infrastructure issues.
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Outdated
if (
error instanceof AuthError &&
(error.reason === "not_authenticated" || error.reason === "expired")
Expand Down
39 changes: 27 additions & 12 deletions test/lib/error-reporting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Unit tests for the central error reporting helper.
*
* Covers:
* - Silencing rules (OutputError / expected AuthError / 401–499 ApiError)
* - Silencing rules (OutputError / ResolutionError / expected AuthError / 401–499 ApiError)
* - Grouping tag extraction (extractResourceKind)
* - Tag enrichment in beforeSend (enrichEventWithGroupingTags)
* - End-to-end behavior of reportCliError (metric emission + capture)
Expand Down Expand Up @@ -244,12 +244,16 @@ describe("classifySilenced", () => {
expect(classifySilenced(new ApiError("x", status))).toBeNull();
});

test("silences ResolutionError as user_input_error", () => {
expect(
classifySilenced(
new ResolutionError("Project 'x'", "not found", "sentry issue list")
)
).toBe("user_input_error");
});

test.each([
["ContextError", new ContextError("Organization", "sentry org view <x>")],
[
"ResolutionError",
new ResolutionError("Project 'x'", "not found", "sentry issue list"),
],
["ValidationError", new ValidationError("bad")],
["SeerError", new SeerError("not_enabled")],
["ConfigError", new ConfigError("bad")],
Expand Down Expand Up @@ -447,14 +451,25 @@ describe("reportCliError integration", () => {
expect(traceErr["cli_error.kind"]).not.toBe(eventErr["cli_error.kind"]);
});

test("captures ResolutionError", () => {
const err = new ResolutionError(
"Project 'x'",
"not found",
"sentry issue list <org>/x"
test("silences ResolutionError and emits metric", () => {
reportCliError(
new ResolutionError(
"Project 'x'",
"not found",
"sentry issue list <org>/x"
)
);
expect(captureSpy).not.toHaveBeenCalled();
expect(metricSpy).toHaveBeenCalledWith(
"cli.error.silenced",
1,
expect.objectContaining({
attributes: expect.objectContaining({
error_class: "ResolutionError",
reason: "user_input_error",
}),
})
);
reportCliError(err);
expect(captureSpy).toHaveBeenCalledWith(err);
});

test("captures SeerError (marketing dashboard)", () => {
Expand Down
Loading