Skip to content

Commit

Permalink
ref(core): improve logging for upload stats (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad authored Feb 22, 2024
1 parent 37754dd commit 7bc7183
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changeset/many-peas-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@codecov/bundler-plugin-core": patch
"@codecov/rollup-plugin": patch
"@codecov/vite-plugin": patch
"@codecov/webpack-plugin": patch
---

Add more detailed logging for upload stats
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const bundleAnalysisPluginFactory = ({
try {
await uploadStats({
preSignedUrl: url,
bundleName: output.bundleName,
message: JSON.stringify(output),
retryCount: userOptions?.retryCount,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe("uploadStats", () => {
setup({ sendError: false });

const data = await uploadStats({
bundleName: "cool-bundle-cjs",
message: "cool-message",
preSignedUrl: "http://localhost/upload/stats/",
retryCount: 0,
Expand All @@ -77,6 +78,7 @@ describe("uploadStats", () => {
let error;
try {
await uploadStats({
bundleName: "cool-bundle-cjs",
message: "cool-message",
preSignedUrl: "",
retryCount: 1,
Expand All @@ -96,6 +98,7 @@ describe("uploadStats", () => {
let error;
try {
await uploadStats({
bundleName: "cool-bundle-cjs",
message: "cool-message",
preSignedUrl: "http://localhost/upload/stats/",
retryCount: 0,
Expand All @@ -115,6 +118,7 @@ describe("uploadStats", () => {
let error;
try {
await uploadStats({
bundleName: "cool-bundle-cjs",
message: "cool-message",
preSignedUrl: "http://localhost/upload/stats/",
retryCount: 0,
Expand Down
8 changes: 6 additions & 2 deletions packages/bundler-plugin-core/src/utils/uploadStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { FailedFetchError } from "../errors/FailedFetchError";

interface UploadStatsArgs {
message: string;
bundleName: string;
preSignedUrl: string;
retryCount?: number;
}

export async function uploadStats({
message,
bundleName,
preSignedUrl,
retryCount = DEFAULT_RETRY_COUNT,
}: UploadStatsArgs) {
Expand Down Expand Up @@ -59,10 +61,12 @@ export async function uploadStats({
}

if (!response.ok) {
red("Failed to upload stats, bad response");
red(
`Failed to upload stats, bad response. Response ${response.status} - ${response.statusText}`,
);
throw new FailedUploadError("Failed to upload stats");
}

green("Successfully uploaded stats");
green(`Successfully uploaded stats for bundle: ${bundleName}`);
return true;
}

0 comments on commit 7bc7183

Please sign in to comment.