Skip to content

Commit ed28e24

Browse files
committed
fix: improve error reporting on upload
1 parent 0fd0e52 commit ed28e24

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/upload.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export async function uploadManifest(
9292
speed: 0,
9393
});
9494

95+
const errors = [];
96+
9597
await mapLimit(
9698
filesToUpload,
9799
NUM_CONCURRENT_UPLOADS,
@@ -114,27 +116,38 @@ export async function uploadManifest(
114116
path: manifestFile.cleanPath,
115117
},
116118
};
117-
// TODO: Veryify this correctly handles errors and retry attempts.
119+
// TODO: Verify this correctly handles errors and retry attempts.
118120
const remotePath = getBlobPath(manifest.site, manifestFile.hash);
119-
const resp = await storageBucket.upload(manifestFile.path, {
120-
// NOTE: `gzip: true` must *not* be set here. Doing so interferes
121-
// with the proxied GCS response. Despite not setting `gzip: true`,
122-
// the response remains gzipped from the proxy server.
123-
destination: remotePath,
124-
metadata: metadata,
125-
});
126-
bytesTransferred += parseInt(resp[1].size);
127-
const elapsed = Math.floor(Date.now() / 1000) - startTime;
128-
const speed = (bytesTransferred / elapsed / (1024 * 1024)).toFixed(2);
129-
bar.update((numProcessedFiles += 1), {
130-
speed: speed,
131-
});
132-
if (numProcessedFiles === numTotalFiles) {
133-
bar.stop();
121+
try {
122+
const resp = await storageBucket.upload(manifestFile.path, {
123+
// NOTE: `gzip: true` must *not* be set here. Doing so interferes
124+
// with the proxied GCS response. Despite not setting `gzip: true`,
125+
// the response remains gzipped from the proxy server.
126+
destination: remotePath,
127+
metadata: metadata,
128+
});
129+
bytesTransferred += parseInt(resp[1].size);
130+
} catch (err) {
131+
errors.push(err);
132+
console.error(`Error uploading -> ${manifestFile.path}`);
133+
console.error(err);
134+
} finally {
135+
const elapsed = Math.floor(Date.now() / 1000) - startTime;
136+
const speed = (bytesTransferred / elapsed / (1024 * 1024)).toFixed(2);
137+
bar.update((numProcessedFiles += 1), {
138+
speed: speed,
139+
});
140+
if (numProcessedFiles === numTotalFiles) {
141+
bar.stop();
142+
}
134143
}
135144
})
136145
);
137146

147+
if (errors.length) {
148+
throw new Error(`Encountered ${errors.length} errors uploading.`);
149+
}
150+
138151
await finalize(googleCloudProject, manifest, ttl);
139152
}
140153
}

0 commit comments

Comments
 (0)