diff --git a/src/data.zig b/src/data.zig index dc013f4..436ec02 100644 --- a/src/data.zig +++ b/src/data.zig @@ -107,7 +107,15 @@ pub const Data = struct { pub fn load() !void { fern.trace().ctx("data.load").log(); const rootdir = try Io.Dir.openDirAbsolute(maivi.io, maivi.config.root, .{}); - const data_dir = try Io.Dir.openDir(rootdir, maivi.io, "data", .{ .iterate = true, .access_sub_paths = true }); + const data_dir = Io.Dir.openDir(rootdir, maivi.io, "data", .{ .iterate = true, .access_sub_paths = true }) catch |err| switch (err) { + error.FileNotFound, error.NotDir => { + fern.warn().ctx("data") + .msg("could not parse data/ directory; it is either missing or not a directory.") + .log(); + return; + }, + else => return err, + }; try parse_dir(data_dir); } @@ -140,6 +148,8 @@ fn parse_dir(dir: Io.Dir) !void { return while (try it.next(maivi.io)) |x| switch (x.kind) { .file => { + if (!(std.mem.endsWith(u8, x.name, ".md") or std.mem.endsWith(u8, x.name, ".tkt"))) continue; + const file = try dir.openFile(maivi.io, x.name, .{ .mode = .read_only }); try parse_file(file); }, diff --git a/src/main.zig b/src/main.zig index 4dc4f78..c798d7a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -53,8 +53,8 @@ fn rev_str(init: std.process.Init, root: []const u8) ![]const u8 { if (init.environ_map.get("MAIVI_REV")) |env_rev| return init.gpa.dupe(u8, env_rev); if (!std.process.can_spawn) { - std.debug.print("error: version info cannot be retrieved from git. version must be provided using -Dversion-string\n", .{}); - std.process.exit(1); + std.log.err("error: version info cannot be retrieved from git. version must be provided using MAIVI_REV\n", .{}); + return error.NoChildProcess; } const git_rev_untrimmed = try spawn(init, &[_][]const u8{ diff --git a/src/root.zig b/src/root.zig index 943a252..9c395c4 100644 --- a/src/root.zig +++ b/src/root.zig @@ -237,7 +237,10 @@ pub fn handletxt(h: *Handler, req: *helpers.Request, res: *helpers.Response) !vo pub fn add_redirects() !void { const root = try std.Io.Dir.openDirAbsolute(io, config.root, .{}); - const contents = try helpers.read_file(allocator, root, "redirect.txt"); + const contents = helpers.read_file(allocator, root, "redirect.txt") catch |err| switch (err) { + error.FileNotFound => return, + else => return err, + }; defer allocator.free(contents); var it = std.mem.splitScalar(u8, contents, '\n');