-
Notifications
You must be signed in to change notification settings - Fork 141
Description
Most errors & warnings are reported using xkb_context_set_log_fn. This works well only for tools in this repo and doesn't provide any actionable information to applications that aren't CLIs.
Many applications that rely on libxkbcommon will not trickle down these errors to the user because it's likely their fault libxkbcommon function failed instead of user error. But none of the failures are recoverable (in practice), because code has to rely on parsing the errors from xkb_context_set_log_fn to know "I used a flag that's not supported by system libxkbcommon", or "the keymap source is malformed".
Returning null works well only if there is a single failure condition.
Further xkb_context_set_log_fn isn't usable directly from Rust FFI anyway because of vararg. It will be in future when c_variadic lands, but until then, I'd have to use a trampoline function in C, to get Rust side to handle xkb_context_set_log_fn + global static mutex + text pattern matching to return Result<Context, ContextError>.
Suggestion
Make all functions that can fail set some errno like static so that code can check the failure condition using xkb_get_error without having to parse human-readable strings. I'm not suggesting errno because only 3/all error values apply and you'd have more freedom if you defined your own enum in xkbcommon-error.h.
Error logging macro could take this additional error code and set the global on its own.
I'm assuming only a single error condition can occur, though it could be a null padded array and there could be an additional one for warnings - depending on your preferences.