aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-05-30 03:50:04 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-05-30 03:50:24 -0700
commitaecc8496921cf5a675a7bd5ce6b068a2cc53092f (patch)
tree7187e57c70ecbc50b389091f52c1e9c93fd00247
parent882559f0b990566259144702578e2a44e4f3bef9 (diff)
downloadbun-aecc8496921cf5a675a7bd5ce6b068a2cc53092f.tar.gz
bun-aecc8496921cf5a675a7bd5ce6b068a2cc53092f.tar.zst
bun-aecc8496921cf5a675a7bd5ce6b068a2cc53092f.zip
Improve error messages when you mistype commands/files/scripts
-rw-r--r--src/cli.zig22
-rw-r--r--src/cli/run_command.zig21
2 files changed, 39 insertions, 4 deletions
diff --git a/src/cli.zig b/src/cli.zig
index ff1a00720..5aa02284d 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -1131,8 +1131,10 @@ pub const Command = struct {
}
}
+ var was_js_like = false;
if (options.defaultLoaders.get(extension)) |loader| {
if (loader.isJavaScriptLike()) {
+ was_js_like = true;
possibly_open_with_bun_js: {
const script_name_to_search = ctx.args.entry_points[0];
@@ -1205,6 +1207,26 @@ pub const Command = struct {
if (try RunCommand.exec(ctx, true, false)) {
return;
}
+
+ Output.prettyErrorln("<r><red>error<r>: Script not found \"<b>{s}<r>\"", .{
+ ctx.positionals[0],
+ });
+ Output.flush();
+ Global.exit(1);
+ }
+
+ if (was_js_like) {
+ Output.prettyErrorln("<r><red>error<r>: Module not found \"<b>{s}<r>\"", .{
+ ctx.positionals[0],
+ });
+ Output.flush();
+ Global.exit(1);
+ } else if (ctx.positionals.len > 0) {
+ Output.prettyErrorln("<r><red>error<r>: File not found \"<b>{s}<r>\"", .{
+ ctx.positionals[0],
+ });
+ Output.flush();
+ Global.exit(1);
}
if (FeatureFlags.dev_only) {
diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig
index 8b0a7bac5..e71748892 100644
--- a/src/cli/run_command.zig
+++ b/src/cli/run_command.zig
@@ -297,13 +297,26 @@ pub const RunCommand = struct {
child_process.stdout_behavior = .Inherit;
const result = child_process.spawnAndWait() catch |err| {
- Output.prettyErrorln("<r><red>error<r>: Failed to run <b>{s}<r> due to error <b>{s}<r>", .{ std.fs.path.basename(executable), @errorName(err) });
+ if (err == error.AccessDenied) {
+ {
+ var stat = std.mem.zeroes(std.c.Stat);
+ const rc = bun.C.stat(std.meta.assumeSentinel(executable, 0), &stat);
+ if (rc == 0) {
+ if (std.os.S.ISDIR(stat.mode)) {
+ Output.prettyErrorln("<r><red>error<r>: Failed to run directory \"<b>{s}<r>\"\n", .{executable});
+ Output.flush();
+ Global.exit(1);
+ }
+ }
+ }
+ }
+ Output.prettyErrorln("<r><red>error<r>: Failed to run \"<b>{s}<r>\" due to error <b>{s}<r>", .{ std.fs.path.basename(executable), @errorName(err) });
Output.flush();
- return false;
+ Global.exit(1);
};
if (result.Exited > 0) {
- Output.prettyErrorln("<r><red>error<r> <b>\"{s}\"<r> exited with {d} status<r>", .{ std.fs.path.basename(executable), result.Exited });
+ Output.prettyErrorln("<r><red>error<r> \"<b>{s}<r>\" exited with {d} status<r>", .{ std.fs.path.basename(executable), result.Exited });
Output.flush();
Global.exit(result.Exited);
}
@@ -947,7 +960,7 @@ pub const RunCommand = struct {
}
if (comptime log_errors) {
- Output.prettyError("<r><red>error:<r> Missing script: <b>{s}<r>\n", .{script_name_to_search});
+ Output.prettyError("<r><red>error:<r> Missing script \"<b>{s}<r>\"\n", .{script_name_to_search});
Output.flush();
Global.exit(0);
}