Skip to content

Commit 6c4377d

Browse files
chore: Add in new debug logs, and expand on current logs (#176)
Add in new debug logs, and expand on current logs.
1 parent 902d662 commit 6c4377d

File tree

7 files changed

+90
-4
lines changed

7 files changed

+90
-4
lines changed

.changeset/moody-camels-accept.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@codecov/bundler-plugin-core": minor
3+
"@codecov/bundle-analyzer": minor
4+
"@codecov/nextjs-webpack-plugin": minor
5+
"@codecov/nuxt-plugin": minor
6+
"@codecov/remix-vite-plugin": minor
7+
"@codecov/rollup-plugin": minor
8+
"@codecov/solidstart-plugin": minor
9+
"@codecov/sveltekit-plugin": minor
10+
"@codecov/vite-plugin": minor
11+
"@codecov/webpack-plugin": minor
12+
---
13+
14+
Add in better debug logging when fetching pre-signed url or uploading stats fail. Update current logs to have more details present.

packages/bundler-plugin-core/src/utils/Output.ts

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { type NormalizedOptions } from "./normalizeOptions.ts";
1111
import { detectProvider } from "./provider.ts";
1212
import { uploadStats } from "./uploadStats.ts";
1313
import { type ValidGitService } from "./normalizeOptions";
14+
import { debug } from "./logging.ts";
1415

1516
class Output {
1617
// base user options
@@ -159,6 +160,10 @@ class Output {
159160
if (emitError) {
160161
throw error;
161162
}
163+
164+
debug(`Error getting pre-signed URL: "${error}"`, {
165+
enabled: this.debug,
166+
});
162167
return;
163168
}
164169

@@ -173,6 +178,7 @@ class Output {
173178
if (emitError) {
174179
throw error;
175180
}
181+
debug(`Error uploading stats: "${error}"`, { enabled: this.debug });
176182
return;
177183
}
178184

packages/bundler-plugin-core/src/utils/__tests__/Output.test.ts

+55
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212

1313
import { detectProvider } from "../provider";
1414
import { Output } from "../Output";
15+
import chalk from "chalk";
1516

1617
vi.mock("../provider");
1718

@@ -338,6 +339,31 @@ describe("Output", () => {
338339
await output.write();
339340
});
340341

342+
it("logs error when debug is enabled", async () => {
343+
setup({ urlSendError: true });
344+
345+
const output = new Output({
346+
apiUrl: "http://localhost",
347+
bundleName: "output-test",
348+
debug: true,
349+
dryRun: false,
350+
enableBundleAnalysis: true,
351+
retryCount: 1,
352+
uploadToken: "token",
353+
});
354+
355+
output.start();
356+
output.end();
357+
358+
await output.write();
359+
360+
expect(consoleSpy).toHaveBeenCalledWith(
361+
`[codecov] ${chalk.italic.yellow(
362+
'Error getting pre-signed URL: "Error: Failed to fetch pre-signed URL"',
363+
)}`,
364+
);
365+
});
366+
341367
it("optionally emits error", async () => {
342368
setup({ urlSendError: true });
343369

@@ -430,6 +456,35 @@ describe("Output", () => {
430456
await output.write();
431457
});
432458

459+
it("logs error when debug is enabled", async () => {
460+
setup({
461+
urlData: { url: "http://localhost/upload/stats/" },
462+
urlStatus: 200,
463+
statsSendError: true,
464+
});
465+
466+
const output = new Output({
467+
apiUrl: "http://localhost",
468+
bundleName: "output-test",
469+
debug: true,
470+
dryRun: false,
471+
enableBundleAnalysis: true,
472+
retryCount: 1,
473+
uploadToken: "token",
474+
});
475+
476+
output.start();
477+
output.end();
478+
479+
await output.write();
480+
481+
expect(consoleSpy).toHaveBeenCalledWith(
482+
`[codecov] ${chalk.italic.yellow(
483+
'Error uploading stats: "Error: Failed to upload stats"',
484+
)}`,
485+
);
486+
});
487+
433488
it("optionally emits error", async () => {
434489
setup({
435490
urlData: { url: "http://localhost/upload/stats/" },

packages/bundler-plugin-core/src/utils/__tests__/getPreSignedURL.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { UploadLimitReachedError } from "../../errors/UploadLimitReachedError.ts
2121
import { UndefinedGitServiceError } from "../../errors/UndefinedGitServiceError.ts";
2222
import { BadOIDCServiceError } from "src/errors/BadOIDCServiceError.ts";
2323
import { FailedOIDCFetchError } from "src/errors/FailedOIDCFetchError.ts";
24+
import Chalk from "chalk";
2425

2526
const mocks = vi.hoisted(() => ({
2627
getIDToken: vi.fn().mockReturnValue(""),
@@ -353,8 +354,10 @@ describe("getPreSignedURL", () => {
353354
error = e;
354355
}
355356

356-
expect(consoleSpy).toHaveBeenCalled();
357357
expect(error).toBeInstanceOf(FailedFetchError);
358+
expect(consoleSpy).toHaveBeenCalledWith(
359+
`[codecov] ${Chalk.red('Failed to get pre-signed URL, bad response: "400 - Bad Request"')}`,
360+
);
358361
});
359362
});
360363

packages/bundler-plugin-core/src/utils/__tests__/uploadStats.test.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { uploadStats } from "../uploadStats";
1414
import { FailedUploadError } from "../../errors/FailedUploadError";
1515
import { FailedFetchError } from "../../errors/FailedFetchError";
1616
import { UploadLimitReachedError } from "../../errors/UploadLimitReachedError";
17+
import Chalk from "chalk";
1718

1819
const server = setupServer();
1920

@@ -120,7 +121,7 @@ describe("uploadStats", () => {
120121

121122
describe("response is not ok", () => {
122123
it("throws a FailedUploadError", async () => {
123-
setup({ sendError: false, status: 400 });
124+
const { consoleSpy } = setup({ sendError: false, status: 400 });
124125

125126
let error;
126127
try {
@@ -135,6 +136,11 @@ describe("uploadStats", () => {
135136
}
136137

137138
expect(error).toBeInstanceOf(FailedUploadError);
139+
expect(consoleSpy).toHaveBeenCalledWith(
140+
`[codecov] ${Chalk.red(
141+
'Failed to upload stats, bad response: "400 - Bad Request"',
142+
)}`,
143+
);
138144
});
139145
});
140146
});

packages/bundler-plugin-core/src/utils/getPreSignedURL.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ export const getPreSignedURL = async ({
116116
}
117117

118118
if (!response.ok) {
119-
red("Failed to get pre-signed URL, bad response");
119+
red(
120+
`Failed to get pre-signed URL, bad response: "${response.status} - ${response.statusText}"`,
121+
);
120122
throw new FailedFetchError("Failed to get pre-signed URL");
121123
}
122124

packages/bundler-plugin-core/src/utils/uploadStats.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export async function uploadStats({
6161

6262
if (!response.ok) {
6363
red(
64-
`Failed to upload stats, bad response. Response ${response.status} - ${response.statusText}`,
64+
`Failed to upload stats, bad response: "${response.status} - ${response.statusText}"`,
6565
);
6666
throw new FailedUploadError("Failed to upload stats");
6767
}

0 commit comments

Comments
 (0)