authorgravatar for h_n91@hotmail.comDraagrenKirneh <h_n91@hotmail.com> 2023-05-13 23:41:11+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-05-13 17:41:11-04:00
log87de8212adac280780900f8a68c302c6bc127c47
tree1a51b7bac906247352ff62aa3ada78146e8fc7c1
parentbc17b38788e173afefc6a4770e5b0610dbe44670
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Improve error handling on dependency download (#15661)

verify ok status on response. improve error messages

1 files changed, 9 insertions(+), 2 deletions(-)

src/Package.zig+9-2
......@@ -489,8 +489,15 @@ fn fetchAndUnpack(
489489 try req.start();
490490 try req.wait();
491491
492 if (req.response.status != .ok) {
493 return report.fail(dep.url_tok, "Expected response status '200 OK' got '{} {s}'", .{
494 @enumToInt(req.response.status),
495 req.response.status.phrase() orelse "",
496 });
497 }
498
492499 const content_type = req.response.headers.getFirstValue("Content-Type") orelse
493 return report.fail(dep.url_tok, "missing Content-Type for '{s}'", .{uri.path});
500 return report.fail(dep.url_tok, "Missing 'Content-Type' header", .{});
494501
495502 if (ascii.eqlIgnoreCase(content_type, "application/gzip") or
496503 ascii.eqlIgnoreCase(content_type, "application/x-gzip") or
......@@ -504,7 +511,7 @@ fn fetchAndUnpack(
504511 // by default, so the same logic applies for buffering the reader as for gzip.
505512 try unpackTarball(gpa, &req, tmp_directory.handle, std.compress.xz);
506513 } else {
507 return report.fail(dep.url_tok, "unknown file extension for path '{s}'", .{uri.path});
514 return report.fail(dep.url_tok, "Unsupported 'Content-Type' header value: '{s}'", .{content_type});
508515 }
509516
510517 // TODO: delete files not included in the package prior to computing the package hash.