fix(install): catch more errors for bun add/update/remove (#10758)

This commit is contained in:
Dylan Conway
2024-05-01 21:42:06 -07:00
committed by GitHub
parent 2a0746d57e
commit 44e09bb7f4
3 changed files with 24 additions and 7 deletions

View File

@@ -308,6 +308,7 @@ pub fn handleRootError(err: anyerror, error_return_trace: ?*std.builtin.StackTra
error.InvalidArgument,
error.@"Invalid Bunfig",
error.InstallFailed,
=> if (!show_trace) Global.exit(1),
error.SyntaxError => {

View File

@@ -7389,15 +7389,35 @@ pub const PackageManager = struct {
}
pub inline fn update(ctx: Command.Context) !void {
try updatePackageJSONAndInstall(ctx, .update, .update);
try updatePackageJSONAndInstallCatchError(ctx, .update, .update);
}
pub inline fn add(ctx: Command.Context) !void {
try updatePackageJSONAndInstall(ctx, .add, .add);
try updatePackageJSONAndInstallCatchError(ctx, .add, .add);
}
pub inline fn remove(ctx: Command.Context) !void {
try updatePackageJSONAndInstall(ctx, .remove, .remove);
try updatePackageJSONAndInstallCatchError(ctx, .remove, .remove);
}
pub fn updatePackageJSONAndInstallCatchError(
ctx: Command.Context,
comptime op: Lockfile.Package.Diff.Op,
comptime subcommand: Subcommand,
) !void {
updatePackageJSONAndInstall(ctx, op, subcommand) catch |err| {
switch (err) {
error.InstallFailed,
error.InvalidPackageJSON,
=> {
const log = &bun.CLI.Cli.log_;
log.printForLogLevel(bun.Output.errorWriter()) catch {};
bun.Global.exit(1);
return;
},
else => return err,
}
};
}
pub inline fn link(ctx: Command.Context) !void {

View File

@@ -3799,10 +3799,6 @@ pub const Package = extern struct {
}
pub fn insert(self: *WorkspaceMap, key: string, value: Entry) !void {
if (comptime Environment.allow_assert) {
assert(!strings.containsChar(key, std.fs.path.sep_windows));
}
if (comptime Environment.isDebug) {
if (!bun.sys.exists(key)) {
Output.debugWarn("WorkspaceMap.insert: key {s} does not exist", .{key});