Skip to content

Commit 8024bd1

Browse files
authored
Merge pull request #308 from techulus/fix/concise-failure-notifications
Keep failure notifications concise
2 parents c5b2bb6 + 79e2bcb commit 8024bd1

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎web/lib/notifications/index.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,17 @@ export async function renderInAppNotification(event: NotificationEvent) {
7979
if (event.kind === "build.failed") {
8080
return {
8181
title: `Build failed: ${context.serviceName}`,
82-
body: event.error ?? `A build for ${context.serviceName} failed.`,
82+
body: `A build for ${context.serviceName} failed.`,
8383
href: `${serviceHref}/builds/${event.buildId}`,
8484
};
8585
}
8686
if (event.kind === "cron.failed") {
8787
return {
8888
title: `Cron failed: ${context.serviceName}`,
89-
body: `${event.path}: ${event.error ?? "Cron request failed"}`,
89+
body:
90+
event.statusCode === null
91+
? `${event.path} failed.`
92+
: `${event.path} failed with HTTP status ${event.statusCode}.`,
9093
href: serviceHref,
9194
};
9295
}

‎web/tests/notifications.test.ts‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ describe("notification pipeline", () => {
9999
).resolves.toBeNull();
100100
});
101101

102-
it("renders cron failures with the service deep link", async () => {
103-
mocks.select.mockReturnValueOnce({
102+
it("omits raw build and cron errors from in-app notifications", async () => {
103+
mocks.select.mockReturnValue({
104104
from: vi.fn(() => ({
105105
innerJoin: vi.fn(() => ({
106106
innerJoin: vi.fn(() => ({
@@ -119,6 +119,19 @@ describe("notification pipeline", () => {
119119
})),
120120
});
121121

122+
await expect(
123+
renderInAppNotification({
124+
kind: "build.failed",
125+
occurrenceId: "build-1",
126+
serviceId: "service-1",
127+
buildId: "build-1",
128+
error: "buildctl failed\n".repeat(1_000),
129+
}),
130+
).resolves.toEqual({
131+
title: "Build failed: API",
132+
body: "A build for API failed.",
133+
href: "/dashboard/projects/cloud/production/services/service-1/builds/build-1",
134+
});
122135
await expect(
123136
renderInAppNotification({
124137
kind: "cron.failed",
@@ -130,7 +143,21 @@ describe("notification pipeline", () => {
130143
}),
131144
).resolves.toEqual({
132145
title: "Cron failed: API",
133-
body: "/jobs/nightly: HTTP status 500",
146+
body: "/jobs/nightly failed with HTTP status 500.",
147+
href: "/dashboard/projects/cloud/production/services/service-1",
148+
});
149+
await expect(
150+
renderInAppNotification({
151+
kind: "cron.failed",
152+
occurrenceId: "cron-2",
153+
serviceId: "service-1",
154+
path: "/jobs/nightly",
155+
statusCode: null,
156+
error: "Connection refused",
157+
}),
158+
).resolves.toEqual({
159+
title: "Cron failed: API",
160+
body: "/jobs/nightly failed.",
134161
href: "/dashboard/projects/cloud/production/services/service-1",
135162
});
136163
});

0 commit comments

Comments
 (0)