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

Provide access to template invocation stack in debug builds #643

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lukemelia
Copy link
Member

@lukemelia lukemelia commented Jun 27, 2020

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @lukemelia!


The fact that that this will only be available in debug builds adds to complexity for consumers of the API and could potentially lead to errors in production if a developer does not realize this.

## Alternatives
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possible alternative would be to provide a public API to emit the same hierarchical message that is used for the backtracking assertion (which is what the on and fn PR linked to above uses). This doesn’t solve the problem 100% (it wouldn’t directly provide access to the line and column info), but it’s fairly close and the plumbing is already largely available (still requires owner access though that might be mitigated by an argument as suggested in the api section). I think this would likely be much easier to implement and could be improved over time to include line and column info when we have solved question 3 above (and in fact, would mean that all of Embers other template error messages like the backtracking rerender one, or on/fn mentioned above, would get that info also).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue Thanks for the quick feedback. I incorporated this and the other feedback you left into the text of the RFC. Feel free to suggest changes if your intention can be expressed more clearly than I captured.

@rwjblue rwjblue self-assigned this Jun 30, 2020
@rwjblue
Copy link
Member

rwjblue commented Jul 24, 2020

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
Copy link
Member

rwjblue commented Jul 31, 2020

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?

@lukemelia
Copy link
Member Author

@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. 👍

@rwjblue
Copy link
Member

rwjblue commented Oct 2, 2020

@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...

@sophie-gg
Copy link

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!

@wagenet
Copy link
Member

wagenet commented Jul 23, 2022

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

@wagenet wagenet added the S-Proposed In the Proposed Stage label Dec 2, 2022
@achambers
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-Proposed In the Proposed Stage T-templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants