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

fix(evented): log an error on invalid type #7067

Merged
merged 5 commits into from
Jan 26, 2021
Merged

fix(evented): log an error on invalid type #7067

merged 5 commits into from
Jan 26, 2021

Conversation

gkatsev
Copy link
Member

@gkatsev gkatsev commented Jan 26, 2021

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.

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.
@@ -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; ` +
Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member Author

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.

@gkatsev gkatsev merged commit 85575db into main Jan 26, 2021
@gkatsev gkatsev deleted the throw-to-error branch January 26, 2021 18:56
alex-barstow added a commit to alex-barstow/video.js that referenced this pull request Apr 8, 2022
misteroneill pushed a commit that referenced this pull request May 16, 2022
)

BREAKING CHANGE: Instead of logging an error message, invalid events will now trigger an `Error` which will terminate the call stack.
misteroneill pushed a commit that referenced this pull request May 19, 2022
)

BREAKING CHANGE: Instead of logging an error message, invalid events will now trigger an `Error` which will terminate the call stack.
misteroneill pushed a commit that referenced this pull request May 23, 2022
)

BREAKING CHANGE: Instead of logging an error message, invalid events will now trigger an `Error` which will terminate the call stack.
misteroneill pushed a commit that referenced this pull request Nov 23, 2022
)

BREAKING CHANGE: Instead of logging an error message, invalid events will now trigger an `Error` which will terminate the call stack.
misteroneill pushed a commit that referenced this pull request Nov 23, 2022
)

BREAKING CHANGE: Instead of logging an error message, invalid events will now trigger an `Error` which will terminate the call stack.
edirub pushed a commit to edirub/video.js that referenced this pull request Jun 8, 2023
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.
edirub pushed a commit to edirub/video.js that referenced this pull request Jun 8, 2023
…pes (videojs#7719)

BREAKING CHANGE: Instead of logging an error message, invalid events will now trigger an `Error` which will terminate the call stack.
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.

2 participants