hare-xdg/format/desktop_entry/error.ha

55 lines
1.8 KiB
Hare
Raw Normal View History

use encoding::utf8;
use io;
// Any error that may occur during parsing.
export type error = !(syntaxerr | io::error | utf8::invalid);
// All syntax errors defined in this module.
export type syntaxerr = !(
2024-10-12 21:34:44 -06:00
invalid_group_header |
2024-10-21 09:38:50 -06:00
invalid_entry |
invalid_ascii |
invalid_escape |
invalid_boolean |
invalid_numeric |
expected_single);
2024-10-12 21:34:44 -06:00
// Returned when a malformed group header is encountered while parsing.
export type invalid_group_header = !void;
// Returned when a malformed entry is encountered while parsing.
export type invalid_entry = !void;
// Returned when ASCII text was expected while parsing, but something else was
2024-10-12 21:34:44 -06:00
// given.
export type invalid_ascii = !void;
// Returned when an invalid escape sequence was enctountered while parsing.
export type invalid_escape = !void;
2024-10-12 20:12:43 -06:00
2024-10-21 09:38:50 -06:00
// Returned when a boolean value was expected while parsing, but something else
// was given.
export type invalid_boolean = !void;
// Returned when a numeric value was expected while parsing, but something else
// was given.
export type invalid_numeric = !void;
// Returned when a singular value was expected while parsing, but multiple
// values were given.
export type expected_single = !void;
// Returns a user-friendly representation of [[error]]. The result may be
// statically allocated.
2024-10-12 21:34:44 -06:00
export fn strerror(err: error) str = match (err) {
case invalid_group_header => yield "invalid group header";
case invalid_entry => yield "invalid entry";
case invalid_ascii => yield "invalid ascii";
case invalid_escape => yield "invalid escape";
2024-10-21 09:38:50 -06:00
case invalid_boolean => yield "invalid boolean";
case invalid_numeric => yield "invalid numeric";
case expected_single => yield "expected single";
case let err: io::error => yield io::strerror(err);
case let err: utf8::invalid => yield utf8::strerror(err);
2024-10-12 20:12:43 -06:00
};