Improve error handling on dependency download (#15661)

verify ok status on response. improve error messages
This commit is contained in:
DraagrenKirneh 2023-05-13 23:41:11 +02:00 committed by GitHub
parent bc17b38788
commit 87de8212ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -489,8 +489,15 @@ fn fetchAndUnpack(
try req.start();
try req.wait();
if (req.response.status != .ok) {
return report.fail(dep.url_tok, "Expected response status '200 OK' got '{} {s}'", .{
@enumToInt(req.response.status),
req.response.status.phrase() orelse "",
});
}
const content_type = req.response.headers.getFirstValue("Content-Type") orelse
return report.fail(dep.url_tok, "missing Content-Type for '{s}'", .{uri.path});
return report.fail(dep.url_tok, "Missing 'Content-Type' header", .{});
if (ascii.eqlIgnoreCase(content_type, "application/gzip") or
ascii.eqlIgnoreCase(content_type, "application/x-gzip") or
@ -504,7 +511,7 @@ fn fetchAndUnpack(
// by default, so the same logic applies for buffering the reader as for gzip.
try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz);
} else {
return report.fail(dep.url_tok, "unknown file extension for path '{s}'", .{uri.path});
return report.fail(dep.url_tok, "Unsupported 'Content-Type' header value: '{s}'", .{content_type});
}
// TODO: delete files not included in the package prior to computing the package hash.