Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors: improve error APIs #130

Merged
merged 4 commits into from
Dec 7, 2024
Merged

errors: improve error APIs #130

merged 4 commits into from
Dec 7, 2024

Conversation

cyphar
Copy link
Member

@cyphar cyphar commented Dec 7, 2024

This primarily contains two useful fixes related to our error APIs:

From the changelog:

  • Error: ErrorKind is now exported, allowing you to programmatically handle
    errors returned by libpathrs. This interface may change in the future (in
    particular, ErrorKind::OsError might change its representation of errno
    values).
  • capi: errors that are returned by libpathrs itself (such as invalid arguments
    being passed by users) will now contain a saved_errno value that makes
    sense for the error type (so ErrorKind::InvalidArgument will result in an
    EINVAL value for saved_errno). This will allow C users to have a nicer
    time handling errors programmatically.

Fixes #60
Fixes #61
Signed-off-by: Aleksa Sarai cyphar@cyphar.com

@cyphar cyphar added this to the 0.2.0 milestone Dec 7, 2024
Previously we had hand-rolled tests for errors. Unfortunately, once we
move to mapping all errors to equivalent errnos for cffi, we will have
to make this checking a little more complicated.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This is particularly important for errors like InvalidArgument that are
generated within the capi code when a C caller provides invalid
arguments. Being able to at least get an -EINVAL for _some_ programmatic
way of matching on argument from C is useful.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
As we plan to export ErrorKind, these kinds of internal errors should be
made opaque since it seems incredibly unlikely that any real users would
ever need to check them.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
ErrorKind is safe for us to export (unlike ErrorImpl) because we can
easily change the concrete types we use for our errors without causing
downstream breakages. Most users almost certainly would prefer something
that looks like std::io::ErrorKind anyway (which matches how we check
for libpathrs errors inside libpathrs as well).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
@cyphar cyphar merged commit bf598df into openSUSE:main Dec 7, 2024
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant