Predefined shared error sets considered harmful
Tags: Linux, UNIX, OS April 5, 2016

Changelog

  • 2016-11-17: title change; paragraph added about manual pages

When we will design the next OS, we should definitely avoid having a static errno variable in user-space. In addition, we should also avoid having a limited predefined set of error codes. Consider the following example (from the Linux DRM subsystem):

The bad practice of using predefined error codes (here ENOENT) makes impossible for the user code to know what is the exact error (here, which kind of entity is not found). We could have returned different error codes for the different errors instead.

When we use a function that uses errno to return its error codes, we already have to read its manual page to know which error codes may be returned. It wouldn’t be more difficult to deal with per-function error codes and it would make error handling much easier. In the given example above, the user-space code has to find the invalid entity by itself, wasting time and programmer’s sanity. Moreover the kernel code locks the entities while it uses them but the user-space code has to deal with potential race conditions.


Comments