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

Enhance error handling #38

Open
blabaere opened this issue Oct 31, 2014 · 5 comments
Open

Enhance error handling #38

blabaere opened this issue Oct 31, 2014 · 5 comments
Labels
Milestone

Comments

@blabaere
Copy link
Collaborator

The native nanomsg lib has quite a lot of constants for the errors, and they should be reported to the nanomsg.rs users. The nn_errno and nn_strerror should be used internally to produce usable results.

@thehydroimpulse thehydroimpulse added this to the Alpha milestone Nov 1, 2014
@blabaere
Copy link
Collaborator Author

blabaere commented Nov 8, 2014

Sadly, the nanomsg error code are platform dependants and I don't know how to port this kind of C code in rust:

#ifndef EBADF
#define EBADF (NN_HAUSNUMERO + 13)
#endif

@thehydroimpulse
Copy link
Owner

We can represent them with cfg and const types.

#[cfg(not(target_os = "windows"))]
use libc::{EPROTONOSUPPORT};

#[cfg(target_os = "windows")]
const EPROTONOSUPPORT: c_int = (NN_HAUSNUMERO + 2)

Some of the errors are already defined in the libc bindings that Rust ships with as they are standard POSIX errors.

The issue is finding out what platforms don't have them defined, I'm guessing windows is the major one that doesn't have them.

Also Rust hardcodes the values for each of these constants while Nanomsg has the NN_HAUSNUMERO random number as to not collide with other OSes error types.

@blabaere
Copy link
Collaborator Author

As usual, there is already some Rust goodness to support what we need. All of it in the trait FromPrimitive. I think I will update ErrorKind to take advantage of this.

@blabaere
Copy link
Collaborator Author

While implementing the part that gets the nanomsg error message attached to the error code, I tried to use c_str_to_static_slice to avoid the copy but failed to import the function so far. @thehydroimpulse, any idea about how to do this ?

@thehydroimpulse
Copy link
Owner

@blabaere mm, trying it on play.rust-lang.org seems to work for me. I'm not sure if that has just been added on a more-recent nightly, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants