agregar identifier a errores y siempre agregar urls

This commit is contained in:
Cat /dev/Nulo 2023-11-28 19:57:35 -03:00
parent ef697d1cae
commit 5870592ac6

View file

@ -64,10 +64,7 @@ async function downloadFromData(jsonUrlString) {
return true; return true;
} catch (error) { } catch (error) {
errorFile.write( errorFile.write(
JSON.stringify({ JSON.stringify(encodeError({ dataset, dist }, error)) + "\n"
url: dist.downloadURL,
...encodeError(error),
}) + "\n"
); );
return false; return false;
} }
@ -99,12 +96,7 @@ async function downloadFromData(jsonUrlString) {
try { try {
await downloadDistWithRetries(job); await downloadDistWithRetries(job);
} catch (error) { } catch (error) {
await errorFile.write( await errorFile.write(JSON.stringify(job, encodeError(error)) + "\n");
JSON.stringify({
url: job.url.toString(),
...encodeError(error),
}) + "\n"
);
nErrors++; nErrors++;
} finally { } finally {
nFinished++; nFinished++;
@ -245,13 +237,26 @@ function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
} }
function encodeError(error) { /**
* @param {{ dataset: Dataset, dist: Distribution, url?: URL }} job
* @param {any} error
*/
function encodeError(job, error) {
const always = {
url: job.url?.toString || job.dist.downloadURL,
datasetIdentifier: job.dataset.identifier,
distributionIdentifier: job.dist.identifier,
};
if (error instanceof StatusCodeError) if (error instanceof StatusCodeError)
return { kind: "http_error", status_code: error.code }; return { ...always, kind: "http_error", status_code: error.code };
else if (error instanceof TooManyRedirectsError) else if (error instanceof TooManyRedirectsError)
return { kind: "infinite_redirect" }; return { ...always, kind: "infinite_redirect" };
else { else {
return { kind: "generic_error", error: error.code || error.message }; return {
...always,
kind: "generic_error",
error: error.code || error.message,
};
} }
} }