Wilkolicious / twitchAdSkip

141 stars 11 forks source link

Resolve undefined error #3

Closed ToxiClay closed 3 years ago

ToxiClay commented 3 years ago

This PR addresses an issue in the spawnObservers function:

const spawnObservers = async function () {
    try {
      const videoPlayerEl = await spawnFindVideoPlayerEl();

      if (!videoPlayerEl) {
        throw new Error('Could not find video player.');
      }
      log('info', 'Success - video player found.');

      spawnVolumeChangeListener(videoPlayerEl);
      spawnVideoPlayerAdSkipObservers(videoPlayerEl);
    } catch (error) {
      log('error', error);
    }
  }

As written, the catch block passes the entire Error object to log(), which in theory should work, as the "message" parameter isn't typed. However, it prints "undefined" to the console instead.

This change attempts to make the function safer by specifically passing the Error.message property instead of passing the entire object.

I'm not sure it worked, though, not completely; running this code causes no error to print at all, even though theoretically the same code runs at the same point in time.

Wilkolicious commented 3 years ago

Appreciate you raising this problem. looking into it, and submitting this PR.

When I wrote this bit of code, the intention was to leave the Error -> String up to the browser renderer - see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString.

If there are errors like this, I want for them to stand out in big, red, and bold messages. The worst case is for errors to be occurring and then to be silenced without the user/maintainer being aware that a problem is present.

This should be fixed in the upcoming commit.