hare-xdg/format/desktop_entry/error.ha

29 lines
1.0 KiB
Hare
Raw Normal View History

2024-10-12 20:12:43 -06:00
// Any error which may be returned from a function in this module.
export type error = !enum {
INVALID_GROUP_HEADER,
INVALID_ENTRY,
// unused for now
DUPLICATE_GROUP,
DUPLICATE_ENTRY,
DUPLICATE_LOCALIZATION,
NO_DEFAULT_VALUE,
ENTRY_OUTSIDE_GROUP,
// --------------
UNSUPPORTED_ESCAPE,
STRING_NOT_ASCII,
};
// Converts a desktop entry [[error]] into a user-friendly string.
export fn strerror(err: error) str = switch {
case INVALID_GROUP_HEADER => yield "invalid group header";
case INVALID_ENTRY => yield "invalid entry";
case DUPLICATE_GROUP => yield "duplicate group";
case DUPLICATE_ENTRY => yield "duplicate entry";
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";
};