mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
fix(install): catch more errors for bun add/update/remove (#10758)
This commit is contained in:
@@ -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 => {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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});
|
||||
|
||||
Reference in New Issue
Block a user