Skip to content

Commit 5a63610

Browse files
committed
Improve some error messages
1 parent 78567d6 commit 5a63610

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/Tags.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn readFile(allocator: std.mem.Allocator, fname: []const u8) !?[:0]const u8 {
114114
}
115115

116116
if (metadata.kind() == .directory) {
117-
return error.NotFile;
117+
return error.IsDir;
118118
}
119119

120120
var array_list = try std.ArrayList(u8).initCapacity(allocator, size + 1);

src/main.zig

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const builtin = @import("builtin");
22
const std = @import("std");
3+
const config = @import("config");
34

45
const Options = @import("Options.zig");
56
const Tags = @import("Tags.zig");
@@ -37,15 +38,24 @@ pub fn main() anyerror!u8 {
3738
const full_fname = if (std.fs.path.isAbsolute(fname))
3839
try allocator.dupe(u8, fname)
3940
else
40-
try std.fs.cwd().realpathAlloc(allocator, fname);
41+
std.fs.cwd().realpathAlloc(allocator, fname) catch |err| switch (err) {
42+
error.FileNotFound => {
43+
std.io.getStdErr().writer().print(
44+
"{s}: Cannot open {s}: File not found.\n",
45+
.{ config.name, fname },
46+
) catch {};
47+
return 22; // EINVAL
48+
},
49+
else => return err,
50+
};
4151
defer allocator.free(full_fname);
4252

4353
tags.findTags(full_fname) catch |err| switch (err) {
44-
error.NotFile => {
45-
try std.io.getStdErr().writer().print(
46-
"Error: {s} is a directory. Arguments must be Zig source files.\n",
47-
.{full_fname},
48-
);
54+
error.IsDir => {
55+
std.io.getStdErr().writer().print(
56+
"{s}: {s} is a directory. Arguments must be Zig source files.\n",
57+
.{ config.name, full_fname },
58+
) catch {};
4959
return 22; // EINVAL
5060
},
5161
else => return err,

0 commit comments

Comments
 (0)