-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
It would be useful if exceptions thrown while evaluating templates and script expressions included the stack trace for the script. Currently the exceptions use the C++ exception system and are simple types deriving from std::exception, and so the catch site will only get a very simple, and often unhelpful within that context, message. e.g. "Invalid argument".
In the simplest case, this would just be the function being invoked by AST nodes just as MemberFuncCall.
A complete implementation should however handle places where there are multiple script stack frames involved:
- executable blocks passed to methods such as
each, which cause a script evaluation to occur within the context of another, or a template method for rendering partials. - places where C++ method implementations might directly call other script method implementations that might throw (e.g. a
link_toRails style helper implemented by acontent_tag).
The trace should include information useful to the template/script writer, and to the controller implementer trying to render the data:
- Include the class and method names of script C++ types.
- Include the file name and location of script/template code.
- Include the method parameters, and any useful variables/attributes (as shared pointers, these can be captured into an exception object safely) for each frame.
Such a stack trace might be:
TagHelper#content_tag(:a, "Help", {href: "/help", "invalid@attr" => "x"})
UrlHelper#link_to("Help", "/help", {"invalid@attr" => "x"})
_nav_bar.html.slim:27
= link_to page[:label], page[:url], "invalid@attr" => "x"
pages = { ... }
page = {label: "Help", url: "/help"}
_nav_bar.html.slim:10
- pages.each do |page|
pages = {...}
layout.html.slim:56
= render partial: "nav_bar", locals: {pages: [{label: "Help", url: "/help"}]}
@title = "Index"
@user = User{name: "test", id: 5}