// SPDX-License-Identifier: AGPL-3.0-only AND BSD-3-Clause // SPDX-FileCopyrightText: 2025 @matrixfurry.com // SPDX-FileCopyrightText: 1987 Regents of the University of California // // Exit code constants and their descriptions are derived from BSD sysexits.h // under the BSD-3-Clause license. const testing = @import("std").testing; pub const metadata = struct { /// Base value for error messages pub const base = 64; /// Maximum listed value pub const max = 78; }; /// Successful pub const ok: u8 = 0; /// The command was used incorrectly (e.g. wrong number of arguments, /// bad flag, bad syntax in a parameter, etc). pub const usage: u8 = 64; /// The input data was incorrect in some way. This should only be used /// for user's data and not system files (which should use `os_file` /// instead). pub const data_err: u8 = 65; /// An input file (not a system file, use `os_file` for that) did not /// exist or was not readable. pub const no_input: u8 = 66; /// The user specified did not exist. pub const no_user: u8 = 67; /// The host specified did not exist. This is used in network requests. pub const no_host: u8 = 68; /// A service is unavailable. This can occur if a support program or /// file does not exist. This can also be used as a catchall message /// when something you wanted to do doesn't work, but you don't know /// why. pub const unavailable: u8 = 69; /// An internal software error has been detected. This should be limited /// to non-operating system related errors if possible. pub const software: u8 = 70; /// An operating system error has been detected. This is intended to be /// used for such things as "cannot fork", "cannot create pipe", etc. pub const os_err: u8 = 71; /// Some system file (e.g. /etc/passwd, /var/run/utmp, etc.) does not /// exist, cannot be opened, or has some sort of error (e.g. syntax /// error). pub const os_file: u8 = 72; /// A user-specified output file cannot be created. pub const cant_create: u8 = 73; /// An error occurred while doing I/O on some file. pub const io_err: u8 = 74; /// Temporary failure, indicating something that is not really an error. /// For example, if a connection could not be created and should be /// reattempted later. pub const temp_fail: u8 = 75; /// The remote system returned something illegal during a protocol /// exchange. pub const protocol: u8 = 76; /// You did not have sufficient permission to perform the operation. /// This is not intended for filesystem problems, which should use /// `no_input` or `cant_create`. but rather for higher level /// permissions. pub const no_permission: u8 = 77; /// Something was found in an unconfigured or misconfigured state. pub const config: u8 = 78; test "metadata matches BSD sysexits" { try testing.expectEqual(metadata.base, 64); try testing.expectEqual(metadata.max, 78); } test "values match BSD sysexits" { try testing.expectEqual(0, ok); try testing.expectEqual(metadata.base, usage); try testing.expectEqual(metadata.base + 1, data_err); try testing.expectEqual(metadata.base + 2, no_input); try testing.expectEqual(metadata.base + 3, no_user); try testing.expectEqual(metadata.base + 4, no_host); try testing.expectEqual(metadata.base + 5, unavailable); try testing.expectEqual(metadata.base + 6, software); try testing.expectEqual(metadata.base + 7, os_err); try testing.expectEqual(metadata.base + 8, os_file); try testing.expectEqual(metadata.base + 9, cant_create); try testing.expectEqual(metadata.base + 10, io_err); try testing.expectEqual(metadata.base + 11, temp_fail); try testing.expectEqual(metadata.base + 12, protocol); try testing.expectEqual(metadata.base + 13, no_permission); try testing.expectEqual(metadata.base + 14, config); } test "metadata.max is correct" { try testing.expect(metadata.max >= ok); try testing.expect(metadata.max >= data_err); try testing.expect(metadata.max >= no_input); try testing.expect(metadata.max >= no_user); try testing.expect(metadata.max >= no_host); try testing.expect(metadata.max >= unavailable); try testing.expect(metadata.max >= software); try testing.expect(metadata.max >= os_err); try testing.expect(metadata.max >= os_file); try testing.expect(metadata.max >= cant_create); try testing.expect(metadata.max >= io_err); try testing.expect(metadata.max >= temp_fail); try testing.expect(metadata.max >= protocol); try testing.expect(metadata.max >= config); }