From ee4a617dffcb1322f0bb0bc9751cee99a83e1f14 Mon Sep 17 00:00:00 2001 From: dave caruso Date: Thu, 20 Jun 2024 18:31:41 -0700 Subject: [PATCH] experiment with enabling error return traces --- build.zig | 29 ++++++++--------------------- src/cli.zig | 6 ++---- src/crash_handler.zig | 5 ++--- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/build.zig b/build.zig index a87737be26..78619d9ed2 100644 --- a/build.zig +++ b/build.zig @@ -273,27 +273,6 @@ pub fn build(b: *Build) !void { } } } - - // Running `zig build` with no arguments is almost always a mistake. - // TODO: revive this error. cannot right now since ZLS runs zig build without arguments - { - // const mistake_message = b.addSystemCommand(&.{ - // "echo", - // \\ - // \\To build Bun from source, please use `bun run setup` instead of `zig build`" - // \\For more info, see https://bun.sh/docs/project/contributing - // \\ - // \\If you want to build the zig code in isolation, run: - // \\ 'zig build obj -Dgenerated-code=./build/codegen [...opts]' - // \\ - // \\If you want to test a compile without emitting an object: - // \\ 'zig build check' - // \\ 'zig build check-all' (run linux+mac+windows) - // \\ - // }); - - // b.default_step.dependOn(&mistake_message.step); - } } pub fn addBunObject(b: *Build, opts: *BunBuildOptions) *Compile { @@ -307,6 +286,13 @@ pub fn addBunObject(b: *Build, opts: *BunBuildOptions) *Compile { .optimize = opts.optimize, .pic = true, .strip = false, // stripped at the end + + // Enable error tracing for all targets so that end users can use bun + // --verbose-error-trace in order to print extra error information. + // + // For performance, see https://ziglang.org/documentation/0.13.0/#toc-Implementation-Details + // When this was added to Bun, no large performance impacts were observed, + .error_tracing = true, }); obj.bundle_compiler_rt = false; @@ -334,6 +320,7 @@ pub fn addBunObject(b: *Build, opts: *BunBuildOptions) *Compile { obj.root_module.valgrind = true; } } + addInternalPackages(b, obj, opts); obj.root_module.addImport("build_options", opts.buildOptionsModule(b)); return obj; diff --git a/src/cli.zig b/src/cli.zig index 94b1089422..ab6c003c38 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -149,13 +149,11 @@ pub const Arguments = struct { const base_params_ = [_]ParamType{ clap.parseParam("--env-file ... Load environment variables from the specified file(s)") catch unreachable, clap.parseParam("--cwd Absolute path to resolve files & entry points from. This just changes the process' cwd.") catch unreachable, + clap.parseParam("--verbose-error-trace Print internal error trace information. Useful for debugging crashes.") catch unreachable, clap.parseParam("-c, --config ? Specify path to Bun config file. Default $cwd/bunfig.toml") catch unreachable, clap.parseParam("-h, --help Display this menu and exit") catch unreachable, clap.parseParam("...") catch unreachable, - } ++ if (builtin.have_error_return_tracing) [_]ParamType{ - // This will print more error return traces, as a debug aid - clap.parseParam("--verbose-error-trace") catch unreachable, - } else [_]ParamType{}; + }; const transpiler_params_ = [_]ParamType{ clap.parseParam("--main-fields ... Main fields to lookup in package.json. Defaults to --target dependent") catch unreachable, diff --git a/src/crash_handler.zig b/src/crash_handler.zig index 9755bb3980..46f96aff38 100644 --- a/src/crash_handler.zig +++ b/src/crash_handler.zig @@ -1351,9 +1351,8 @@ fn handleErrorReturnTraceExtra(err: anyerror, maybe_trace: ?*std.builtin.StackTr /// single line (the error name) is printed. When this is set, we will print /// trace strings for those errors (or full stacks in debug builds). /// -/// This can be enabled by passing `--verbose-error-trace` to the CLI. -/// In release builds with error return tracing enabled, this is also exposed. -/// You can test if this feature is available by checking `bun --help` for the flag. +/// This can be enabled by passing `--verbose-error-trace` to the CLI, which +/// is enabled in release mode to aid debugging. pub inline fn handleErrorReturnTrace(err: anyerror, maybe_trace: ?*std.builtin.StackTrace) void { handleErrorReturnTraceExtra(err, maybe_trace, false); }