-
Notifications
You must be signed in to change notification settings - Fork 320
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
Replace Skip link errors with ElementError
#4219
Conversation
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for 70265f1 |
3d0cc44
to
f825dba
Compare
* @throws {MissingElementError} If the element with the specified ID is not found | ||
* @throws {ElementError} when $module is not set or the wrong type | ||
* @throws {ElementError} when $module.hash does not contain a hash | ||
* @throws {ElementError} when the linked element is missing or the wrong type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romaricpascal Just flagging that @domoscargin has documented @throw
for JSDoc output
We only need them on public methods but I've updated them based on the test names
Presume this is something we'd want to roll out elsewhere after #4072
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we'll want all our errors documented with @throws
on the constructors once we've got the full extent of what's being thrown and the wordings.
try { | ||
const $linkedElement = this.getLinkedElement() | ||
this.$linkedElement = $linkedElement | ||
} catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@domoscargin It got a bit tricky to handle all the error variations in a try/catch
Now that we have ElementError
we can throw the same error type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
I have a query, but it's non-blocking.
For example, Skip link throws errors when its element property `$module.hash` does not contain a hash
f825dba
to
70265f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No blockers for me, though we may revisit messages once we have a final wording in #4072.
* @throws {MissingElementError} If the element with the specified ID is not found | ||
* @throws {ElementError} when $module is not set or the wrong type | ||
* @throws {ElementError} when $module.hash does not contain a hash | ||
* @throws {ElementError} when the linked element is missing or the wrong type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we'll want all our errors documented with @throws
on the constructors once we've got the full extent of what's being thrown and the wordings.
throw new ElementError(this.$module, { | ||
componentName: 'Skip link', | ||
identifier: '$module.hash', | ||
expectedType: 'string' | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remark Clever way to sort an "is not of the expected type" message. I think that's fine for this PR, but we may have to revisit once we settle on wording for the error messages depending on how things end up worded. Depending on our public API for errors, that might even be able to wait post v5, and be all internal anyways.
getFragmentFromUrl(url) { | ||
if (url.indexOf('#') === -1) { | ||
return undefined | ||
} | ||
|
||
return this.$module.hash.split('#').pop() | ||
return url.split('#').pop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good shout! 🙌🏻 Looks like a little function ripe for no longer living in these classes now they're both aligned (especially as it does not reference this
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 😊
name: 'MissingElementError', | ||
message: 'Skip link: $module "href" attribute does not contain a hash' | ||
name: 'ElementError', | ||
message: 'Skip link: $module.hash is not of type "string"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flagging for #4072 that we could harmonise the message for when an element is missing to " is missing" and use this here instead of discussing the type. Up for discussion when tackling that later issue 😊
Replace Skip link errors with `ElementError`
This PR replaces Skip link
$module
and$module.hash
errors withElementError
to close:MissingElementError
withElementError
#4209