rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Provide access to template invocation stack in debug builds

Open lukemelia opened this issue 4 years ago • 7 comments

Rendered

lukemelia avatar Jun 27 '20 11:06 lukemelia

FYI - I brought this up at todays core team meeting. A few general notes/observations:

  • There is brought consensus that we should provide a good solution to the problem described here (addons and app code being able to provide useful + actionable messages for template invocations)
  • @pzuraq brought up a concern about the internal API that I was referring to (that is used by on/fn and the backtracking re-render assertion) which leverages the debug render tree. Specifically, that we are likely to move more and more of the underlying logic into glimmer-vm (currently part of it lives in glimmer-vm and part lives in Ember). I think that both @pzuraq and I came to the conclusion that as long as the specifics of the API that we provide aren't super super locked down we shouldn't have an issue.
  • @chancancode and @wycats mentioned that this may be a good candidate for nice integration with the ongoing tooling efforts over in https://github.com/emberjs/ember-debug

In the end, the core team decided to defer to a smaller group (the glimmer team) for more detailed feedback. I'll try to remember to chime back in here once we've had that discussion.

rwjblue avatar Jul 24 '20 20:07 rwjblue

We discussed this again at the most recent GlimmerVM team meeting, and think we have a viable path forward that we are confident we can support over time. We are thinking something like:

  • expose a method that folks can call during rendering that returns a string they can use in their own error messages (e.g. getRenderInvocationInfo())
    • the method returns an "opaque" string (e.g. the exact verbiage / contents can change over time)
    • the intent is that when combined with other error message content, the resulting value will provide context to the developer
    • the method returns '' in some cases (production builds)

This could be used like:

export default class extends Component {
  renderLocation = getRenderInvocationInfo();

  @action doSomething() {
    if (someBadCondition()) {
      throw new Error(`Don't do that! ${this.renderLocation}`);
    }
  }
}

The fact that it returns an opaque string with the "best effort" promise means that it is quite likely that we can maintain this contract over time (vs providing more structured output like in ember-template-invocation-location addon).

We still need to decide exact method names and module paths, but the VM team is generally 👍 to this rough sketch.

@lukemelia - What do you think? Do you think that is "enough" to satisfy the motivation here?

rwjblue avatar Jul 31 '20 22:07 rwjblue

@rwjblue I think this sounds like a good approach. I had originally thought of something structured so that the most useful error messages could be crafted, but this has obvious advantages and doesn't preclude exposing more structured detail it proves to be necessary in the future. 👍

lukemelia avatar Aug 02 '20 13:08 lukemelia

@lukemelia - Just checking in here, have any time to update the doc? I think @pzuraq has most of the plumbing landed in glimmer-vm, so looking forward moving the API forward...

rwjblue avatar Oct 02 '20 18:10 rwjblue

I would just like to +1 this. I'm learning ember, and this would be extremely useful. Would make debugging and locating errors much faster, and the learning process smoother!

sophie-gg avatar Nov 21 '20 22:11 sophie-gg

@lukemelia just a reminder that this could use to be updated.

wagenet avatar Jul 23 '22 18:07 wagenet

This seems useful and sounds like it had some interest initially. Does this still make sense in the Polaris world and should we pick it back up?

achambers avatar Aug 11 '23 14:08 achambers