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

Better errors from visitable #640

Merged
merged 5 commits into from Mar 13, 2024
Merged

Conversation

simonihmig
Copy link
Contributor

This adds the actual error message from Ember's router to the (too generic) message from visitable. This is especially important when your test needs to know what kind of error was triggered. For example some tests might want to handle TransitionAborted errors differently, see emberjs/ember-test-helpers#332 (comment).

This adds the actual error message from Ember's router to the (too generic) message from `visitable`. This is especially important when your test needs to know what kind of error was triggered. For example some tests might want to handle `TransitionAborted` errors differently, see emberjs/ember-test-helpers#332 (comment).
@ro0gr
Copy link
Collaborator

ro0gr commented Mar 1, 2024

Hey @simonihmig 👋 Thanks!

I think I'm not a fan to add external error messages into the page object error messages at the first place. This may be a breaking change for some test suites if we merge it as is. And this can break test suites later, when someone upgrades the @ember/test-helpers. That was one of the reasons we've migrated to a page object's own error message before(#606), as a part of the v2 breaking realease.

I think a good enough tradeoff could be to keep the original error in the Error.cause. I believe, in this case the change can be backward compatible, and if someone really needs it they can use it(on their own risk), and it potentially allows for a better control over the original error type etc.. WDYT?

@ro0gr
Copy link
Collaborator

ro0gr commented Mar 2, 2024

This may be a breaking change for some test suites if we merge it as is.

Ok I think I overrated the breaking nature of this change a bit. But I still feel like the cause is a proper place to store this kind of info.

@simonihmig
Copy link
Contributor Author

Ok I think I overrated the breaking nature of this change a bit.

No worries! Normally I wouldn't think of the error message as something covered by the public API contract to be always the same. But actually, the changes in ecpo v2 were of a breaking nature to us because of this, as we had some checks like e.message === 'TransitionAborted' in place (for that very specific use case only) that broke with the upgrade.

I agree that we should make use of .cause, I forgot that this existed, so thanks for the suggestion, it totally makes sense!

However, I am still wondering if we should also update the message itself? You can only make use of .cause when actually running the test and putting a breakpoint somewhere to inspect it, right? But giving a better message in e.g. CI logs would be valuable for DX, to be able to immediately understand why the tests are failing. Could be an error thrown in a route hook, could be an error response in the (mocked) API, could be that transition error thing or whatnot...

But I'll leave that up to you to decide. My primary use case of being able to detect TransitionAborted cases is perfectly served with the .cause property! Will update this PR once this discussion has been settled! :)

@ro0gr
Copy link
Collaborator

ro0gr commented Mar 4, 2024

But giving a better message in e.g. CI logs would be valuable for DX

I think you are right. Let's do it!

As a side note, I think it does also make sense to express the cause via jsdoc, so a future user is aware of this capability.

@simonihmig
Copy link
Contributor Author

I just pushed this commit, which tries to implement the suggestion. However, there is a bit still left for discussion, because I realized that the error rethrown from the visitable helper is actually not the one received by the user, as it is catched and rethrown again by the "better-errors" functionality. And that already has opinions about cause here, which I didn't want to break by passing the original error. What I did instead was to just pass the message of e.cause if it exists, but keep the rest in place. Does that make sense?

@ro0gr
Copy link
Collaborator

ro0gr commented Mar 9, 2024

Oh.. yes, what you say makes sense. I didn't expect the existing cause stuff would lead to an issue. I'll check if I can fix that and pr the fix against your branch, or merge your pr as is.

...under the `cause.error`
in the `visitable` error instance
@ro0gr
Copy link
Collaborator

ro0gr commented Mar 11, 2024

@simonihmig please take a look simonihmig#1

@simonihmig
Copy link
Contributor Author

Thanks @ro0gr, merged it, so this PR should be good to go now I hope!

@@ -1,6 +1,7 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"compilerOptions": {
"target": "es2022",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm just wondering if this was needed for some reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, right... this was needed to make TS understand that Error#cause is a thing. Was getting type errors without it when trying to access .cause.

@ro0gr
Copy link
Collaborator

ro0gr commented Mar 13, 2024

Awesome. I've just left one minor question. Going to publish this tonight.

@simonihmig
Copy link
Contributor Author

I've just left one minor question. Going to publish this tonight.

What is the question? 😄
This one? #640 (comment)

@ro0gr ro0gr merged commit ed51bb1 into san650:master Mar 13, 2024
14 checks passed
@simonihmig simonihmig deleted the better-visit-errors branch March 13, 2024 14:21
@ro0gr
Copy link
Collaborator

ro0gr commented Mar 16, 2024

Hey, I've just released this https://github.com/san650/ember-cli-page-object/releases/tag/v2.3.0

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

Successfully merging this pull request may close these issues.

None yet

2 participants