-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
fix(evented): log an error on invalid type #7067
Conversation
Follow up from #6982. We previously threw an error but we've seen it happen unexpectedly. Instead, we should log an error. Here, if we have a `log` object on the current object, we should use it, otherwise, we use a default `log` object.
src/js/mixins/evented.js
Outdated
@@ -444,7 +445,7 @@ const EventedMixin = { | |||
const type = event && typeof event !== 'string' ? event.type : event; | |||
|
|||
if (!isValidEventType(type)) { | |||
throw new Error(`Invalid event type for ${objName(this)}#trigger; ` + | |||
(this.log || log).error(`Invalid event type for ${objName(this)}#trigger; ` + |
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.
This allows us to use the player/plugin/etc log if it exists, for example:
> player.controlBar.trigger({})
< VIDEOJS: ERROR: Invalid event type for ControlBar#trigger; must be a non-empty string or object with a type key that has a non-empty value.
> player.trigger({})
< VIDEOJS: vjs_video_3: ERROR: Invalid event type for null#trigger; must be a non-empty string or object with a type key that has a non-empty value.
'must be a non-empty string or object with a type key that has a non-empty value.'; | ||
|
||
if (event) { | ||
(this.log || log).error(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.
should we return no matter what if we don't get a valid event 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.
I think to reduce potential breakage, we want to try and continue through to the next part here and not return early.
Though, if they got here there's probably something wrong, but it could still be working in some way, for better and worse.
Follow up from videojs#6982. We previously threw an error, but we've seen it happen unexpectedly. Instead, we should log an error. We will still throw an error if the event is undefined or null. Here, if we have a `log` object on the current object, we should use it, otherwise, we use a default `log` object.
…pes (videojs#7719) BREAKING CHANGE: Instead of logging an error message, invalid events will now trigger an `Error` which will terminate the call stack.
Follow up from #6982. We previously threw an error, but we've seen it
happen unexpectedly. Instead, we should log an error.
Here, if we have a
log
object on the current object, we should use it,otherwise, we use a default
log
object.