Better errors

This commit is contained in:
Sasha Koshka 2024-10-12 23:34:44 -04:00
parent 427d30c255
commit 3e72688127

View File

@ -1,28 +1,27 @@
// Any error which may be returned from a function in this module. // Any error which may be returned from a function in this module.
export type error = !enum { export type error = !(
INVALID_GROUP_HEADER, invalid_group_header |
INVALID_ENTRY, invalid_entry |
// unused for now invalid_ascii |
DUPLICATE_GROUP, invalid_escape);
DUPLICATE_ENTRY,
DUPLICATE_LOCALIZATION, // Returned when a malformed group header is encountered while parsing.
NO_DEFAULT_VALUE, export type invalid_group_header = !void;
ENTRY_OUTSIDE_GROUP,
// -------------- // Returned when a malformed entry is encountered while parsing.
UNSUPPORTED_ESCAPE, export type invalid_entry = !void;
STRING_NOT_ASCII,
}; // Returned when ASCII text was expected, while parsing, but something else was
// given.
export type invalid_ascii = !void;
// Returned when an invalid escape sequence was enctountered while parsing.
export type invalid_escape = !void;
// Converts a desktop entry [[error]] into a user-friendly string. // Converts a desktop entry [[error]] into a user-friendly string.
export fn strerror(err: error) str = switch { export fn strerror(err: error) str = match (err) {
case INVALID_GROUP_HEADER => yield "invalid group header"; case invalid_group_header => yield "invalid group header";
case INVALID_ENTRY => yield "invalid entry"; case invalid_entry => yield "invalid entry";
case DUPLICATE_GROUP => yield "duplicate group"; case invalid_ascii => yield "invalid ascii";
case DUPLICATE_ENTRY => yield "duplicate entry"; case invalid_escape => yield "invalid escape";
case DUPLICATE_LOCALIZATION => yield "duplicate localization";
case NO_DEFAULT_VALUE => yield "no default value";
case ENTRY_OUTSIDE_GROUP => yield "entry outside group";
case UNSUPPORTED_ESCAPE => yield "unsupported escape";
case STRING_NOT_ASCII => yield "string not ascii";
case => yield "unknown";
}; };