Skip to content

Commit

Permalink
util.zig: more helpful error message when zig is not in path
Browse files Browse the repository at this point in the history
  • Loading branch information
erg committed Jan 16, 2025
1 parent 5ebb60d commit b5ae4ec
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions cli/util.zig
Original file line number Diff line number Diff line change
Expand Up @@ -169,34 +169,38 @@ pub fn runCommandInDir(allocator: std.mem.Allocator, argv: []const []const u8, d
};
defer if (dir == .dir) allocator.free(cwd_path);

const result = try std.process.Child.run(.{
const result = std.process.Child.run(.{
.allocator = allocator,
.argv = argv,
.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.stderr);

const command = try std.mem.join(allocator, " ", argv);
defer allocator.free(command);

std.debug.print("[exec] {s}", .{command});

if (result.term.Exited != 0) {
printFailure();
std.debug.print(
\\
\\Error running command: {s}
\\
\\[stdout]:
\\
\\{s}
\\
\\[stderr]:
\\
\\{s}
\\
, .{ command, result.stdout, result.stderr });
if (result.stdout.len > 0) {
std.debug.print("\n[stdout]:\n{s}\n", .{result.stdout});
}
if (result.stderr.len > 0) {
std.debug.print("\n[stderr]:\n{s}\n", .{result.stderr});
}
return error.JetzigCommandError;
} else {
printSuccess();
Expand Down Expand Up @@ -290,8 +294,6 @@ pub fn environmentBuildOption(environment: cli.Environment) []const u8 {
};
}



pub fn unicodePrint(comptime fmt: []const u8, args: anytype) !void {
if (builtin.os.tag == .windows) {
// Windows-specific code
Expand Down Expand Up @@ -320,6 +322,6 @@ const UTF8ConsoleOutput = struct {
}

fn deinit(self: UTF8ConsoleOutput) void {
_ = std.os.windows.kernel32.SetConsoleOutputCP(self.original);
_ = std.os.windows.kernel32.SetConsoleOutputCP(self.original);
}
};
};

0 comments on commit b5ae4ec

Please sign in to comment.