errors.ha (756B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 use encoding::utf8; 5 use fs; 6 use io; 7 use net::ip; 8 9 // Returned when an invalid host line was found. 10 export type invalid = !void; 11 12 // All possible errors returned from this module. 13 export type error = !(io::error | invalid | utf8::invalid | ip::invalid 14 | fs::error); 15 16 // Converts an [[error]] to a human-friendly representation. 17 export fn strerror(err: error) const str = { 18 match (err) { 19 case invalid => 20 return "Host file format is invalid"; 21 case utf8::invalid => 22 return "File is invalid UTF-8"; 23 case ip::invalid => 24 return "IP address is invalid"; 25 case let err: io::error => 26 return io::strerror(err); 27 case let err: fs::error => 28 return fs::strerror(err); 29 }; 30 };