Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Add Optional error codes to identify errors #60

Open
callicles opened this issue Nov 14, 2016 · 9 comments
Open

Add Optional error codes to identify errors #60

callicles opened this issue Nov 14, 2016 · 9 comments

Comments

@callicles
Copy link

callicles commented Nov 14, 2016

Hi,

When interacting rust code with other languages, we can't do pattern matching on error types.
As a consequence being able to add a method to define error code according of the type of the error would be great.

Thank you

@Yamakaky
Copy link
Contributor

What do you mean? Do you have an example?

@callicles
Copy link
Author

I am building a library that's called from languages. More explicitly, I am writing multiple plugins for IDEs. Each IDE has its own plugin and system language. As such, not to have to rewrite most of the logic, I use rust as a common backend. I use Json to communicate, transmitted with pointers as strings to communicate between the rust and the plugin. One of the shortcoming of that serialization are two things with error-chain I need to be able to serialize the backtrace to transmit it to the calling plugin. And I need some way of identifying errors based on some other thing than the message error itself. That's why I want to add error codes, to be able to send error identification information through the frontier between rust and the plugin. (Hope that's more clear)

@Yamakaky
Copy link
Contributor

You mean that you want to be able to associate some data to an error?

@callicles
Copy link
Author

callicles commented Nov 15, 2016

yes, data conditional to the type of the error

@Yamakaky
Copy link
Contributor

You can already do that for normal errors, and you would like to do it for links and foreign_links errors? Any idea about which macro change you would like?

@callicles
Copy link
Author

What do you mean, I can do it for normal errors? In the errors block within the error_chain macro?

As for the macro change we could have a codes block that associates foreign_links and links to a string (or usize) code like so:

codes {
    Temp, "#0001";
}

To access it we could have a .code method on the error that returns the corresponding error code.

@Yamakaky
Copy link
Contributor

you can do

errors {
    Temp(code: u16) {}
}

I don't really see what would be the benefit. I thought you where talking about getting the code above to work with links

@callicles
Copy link
Author

I was, the Temp was supposed to be a foreign link. In the example I went for the result of the mapping.

However, if we can use the result of the mapping to add custom fields then there might not need any addition to the macro.

@Yamakaky
Copy link
Contributor

Yamakaky commented Nov 17, 2016

something like this then?

foreign_links {
    io::Error, Io<u16>;
}

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

No branches or pull requests

2 participants