From 596d5a24b51bbee6895b9cce7768133f3523241e Mon Sep 17 00:00:00 2001 From: fjebaker Date: Tue, 12 Nov 2024 14:49:48 +0100 Subject: [PATCH] fix(compile): better error message invoke error If the command used to compile cannot be found, we now give a sensible error message, and checks the exit code of the child. --- src/commands/compile.zig | 12 +++++++++++- src/topology/TextCompiler.zig | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/commands/compile.zig b/src/commands/compile.zig index 26b4ced..b0df192 100644 --- a/src/commands/compile.zig +++ b/src/commands/compile.zig @@ -123,7 +123,17 @@ fn compileNote( const ext = note.getExtension(); const compiler = try self.getCompiler(allocator, root, ext); - return try compiler.compileNote(allocator, note, root, .{}); + return compiler.compileNote(allocator, note, root, .{}) catch |err| + switch (err) { + error.FileNotFound => { + return cli.throwError( + err, + "No such command: '{s}'", + .{compiler.command[0]}, + ); + }, + else => return err, + }; } fn getCompiler( diff --git a/src/topology/TextCompiler.zig b/src/topology/TextCompiler.zig index 34d9dce..cb6f6e4 100644 --- a/src/topology/TextCompiler.zig +++ b/src/topology/TextCompiler.zig @@ -342,7 +342,9 @@ fn runCommand( const term = try proc.wait(); switch (term) { - .Exited => {}, + .Exited => |code| { + if (code != 0) return Error.CompileError; + }, .Signal => return Error.CompileInterrupted, else => return Error.CompileError, }