better error messages

This commit is contained in:
Andrew Kelley 2024-10-19 00:09:52 -07:00
parent d1ecb742ec
commit 3cc19cd865
2 changed files with 7 additions and 7 deletions

View File

@ -1383,12 +1383,12 @@ pub const File = struct {
for (comp.link_inputs) |input| { for (comp.link_inputs) |input| {
base.loadInput(input) catch |err| switch (err) { base.loadInput(input) catch |err| switch (err) {
error.LinkFailure => return, // error reported via link_diags error.LinkFailure => return, // error reported via link_diags
else => |e| { else => |e| switch (input) {
if (input.path()) |path| { .dso => |dso| comp.link_diags.addParseError(dso.path, "failed to parse shared library: {s}", .{@errorName(e)}),
comp.link_diags.addParseError(path, "failed to parse linker input: {s}", .{@errorName(e)}); .object => |obj| comp.link_diags.addParseError(obj.path, "failed to parse object: {s}", .{@errorName(e)}),
} else { .archive => |obj| comp.link_diags.addParseError(obj.path, "failed to parse archive: {s}", .{@errorName(e)}),
comp.link_diags.addError("failed to {s}: {s}", .{ input.taskName(), @errorName(e) }); .res => |res| comp.link_diags.addParseError(res.path, "failed to parse Windows resource: {s}", .{@errorName(e)}),
} .dso_exact => comp.link_diags.addError("failed to handle dso_exact: {s}", .{@errorName(e)}),
}, },
}; };
} }

View File

@ -3910,7 +3910,7 @@ fn testUnknownFileTypeError(b: *Build, opts: Options) *Step {
exe.linkLibC(); exe.linkLibC();
expectLinkErrors(exe, test_step, .{ expectLinkErrors(exe, test_step, .{
.contains = "error: failed to parse shared object: BadMagic", .contains = "error: failed to parse shared library: BadMagic",
}); });
return test_step; return test_step;