Skip to content

Handling of internal plugin errors #15509

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

Closed
kmcallister opened this issue Jul 7, 2014 · 7 comments
Closed

Handling of internal plugin errors #15509

kmcallister opened this issue Jul 7, 2014 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-plugins Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html

Comments

@kmcallister
Copy link
Contributor

Plugins can fail in ways that aren't the fault of the code being compiled. This could be an internal error in the plugin (which is still different from an ICE in Rust itself), or something like failure to load an external configuration file.

Ideally, plugins would call the usual methods like bug, err, span_bug, etc., and the resulting messages would include the name of the plugin crate. Unfortunately we can't do this by setting session state about which plugin is running, because they can call back into librustc and errors there shouldn't be reported as plugin errors. We could introduce plugin_bug, plugin_err, plugin_span_bug, etc, but this API duplication is ugly, and you have to remember to use different methods when writing plugins.

The nicer (though harder-to-implement) solution is to have these functions walk the stack and then look at which shared object their caller was defined in. In glibc this can be done with backtrace() and dladdr(), but I don't know how hard it is on other platforms.

Whatever we do, we should also make these error methods accessible from the Registry, for use handling errors that occur during plugin initialization.

@thestinger
Copy link
Contributor

It's not possible to walk the stack in the general case, it depends on debug symbols unless you disable frame pointer elimination. It's fine to depend on it for debuggers but supporting backtraces elsewhere will hurt the performance of the language.

@kmcallister
Copy link
Contributor Author

Can we put an attribute on err etc. to disable frame pointer elimination for those calls? Or we could make them into macros.

@ghost
Copy link

ghost commented Jul 7, 2014

We could introduce plugin_bug, plugin_err, plugin_span_bug, etc, but this API duplication is ugly, and you have to remember to use different methods when writing plugins.

Is this really a problem? ExtCtxt already includes the whole family of diagnostic methods. I think it'd be fair that those should always be used so that messages are properly classified.

ICEs will still need to be handled properly, though (at the very least, they shouldn't include the bug report URL of the Rust compiler).

@huonw
Copy link
Member

huonw commented Jul 7, 2014

cc me

@huonw
Copy link
Member

huonw commented Jul 7, 2014

Unfortunately we can't do this by setting session state about which plugin is running, because they can call back into librustc and errors there shouldn't be reported as plugin errors

Registry could track which plugin it is initialising, so registry.span_err(...) would include the plugin name. Or, it could just track the span of the extern crate/source of the plugin (#15446) internally and expose err, warning which default to highlighting that source. That is, if plugin calls registry.err("foo bar baz"), then

#[phase(plugin)]
extern crate plugin;

would emit

1:1:1:10: error: foo bar baz
1: extern crate plugin;
   ^~~~~~~~~~~~~~~~~~~

One possibility would be handle this as a separate struct, so the signature of plugin_registrar becomes fn register(reg: &mut Registry, info: &PluginInfo), with PluginInfo containing the imported name, span, and the various err methods.

@steveklabnik
Copy link
Member

Traige: no specific improvements I know of.

@steveklabnik
Copy link
Member

Triage: we now have accepted an RFC for procedural macros; I believe all of the design work that this ticket is about is happening as part of that effort. I'm going to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-plugins Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html
Projects
None yet
Development

No branches or pull requests

4 participants