Merge pull request #143 from erg/fix-142-jetzig-init

util.zig: more helpful error message when `zig` is not in path
This commit is contained in:
bobf 2025-02-01 11:53:50 +00:00 committed by GitHub
commit 1b5c72b75f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -169,34 +169,38 @@ pub fn runCommandInDir(allocator: std.mem.Allocator, argv: []const []const u8, d
}; };
defer if (dir == .dir) allocator.free(cwd_path); defer if (dir == .dir) allocator.free(cwd_path);
const result = try std.process.Child.run(.{ const result = std.process.Child.run(.{
.allocator = allocator, .allocator = allocator,
.argv = argv, .argv = argv,
.cwd = cwd_path, .cwd = cwd_path,
}); }) catch |err| {
switch (err) {
error.FileNotFound => {
printFailure();
const cmd_str = try std.mem.join(allocator, " ", argv);
defer allocator.free(cmd_str);
std.debug.print(
\\Error: Could not execute command - executable '{s}' not found
\\Command: {s}
\\Working directory: {s}
\\
, .{ argv[0], cmd_str, cwd_path });
return error.JetzigCommandError;
},
else => return err,
}
};
defer allocator.free(result.stdout); defer allocator.free(result.stdout);
defer allocator.free(result.stderr); defer allocator.free(result.stderr);
const command = try std.mem.join(allocator, " ", argv);
defer allocator.free(command);
std.debug.print("[exec] {s}", .{command});
if (result.term.Exited != 0) { if (result.term.Exited != 0) {
printFailure(); printFailure();
std.debug.print( if (result.stdout.len > 0) {
\\ std.debug.print("\n[stdout]:\n{s}\n", .{result.stdout});
\\Error running command: {s} }
\\ if (result.stderr.len > 0) {
\\[stdout]: std.debug.print("\n[stderr]:\n{s}\n", .{result.stderr});
\\ }
\\{s}
\\
\\[stderr]:
\\
\\{s}
\\
, .{ command, result.stdout, result.stderr });
return error.JetzigCommandError; return error.JetzigCommandError;
} else { } else {
printSuccess(); printSuccess();
@ -290,8 +294,6 @@ pub fn environmentBuildOption(environment: cli.Environment) []const u8 {
}; };
} }
pub fn unicodePrint(comptime fmt: []const u8, args: anytype) !void { pub fn unicodePrint(comptime fmt: []const u8, args: anytype) !void {
if (builtin.os.tag == .windows) { if (builtin.os.tag == .windows) {
// Windows-specific code // Windows-specific code
@ -320,6 +322,6 @@ const UTF8ConsoleOutput = struct {
} }
fn deinit(self: UTF8ConsoleOutput) void { fn deinit(self: UTF8ConsoleOutput) void {
_ = std.os.windows.kernel32.SetConsoleOutputCP(self.original); _ = std.os.windows.kernel32.SetConsoleOutputCP(self.original);
} }
}; };