Fix a bug when there's an error when starting or destroying the bar #538
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Presumably this is incredibly unlikely to happen as I couldn't see any issues about this, and it's a bug that has been around for a very long time.
There's an error class that gets defined,
NoTargetError
, that inherits from Error and is used inBar.prototype.getElement
when the target element doesn't exist in the DOM. However, there's a couple of places in the code whereNoTargetError
gets redefined inside ofcatch {}
blocks, and assigned to the error instance instead. Later, if the code tries tothrow new NoTargetError
again, it'll fail because the error instance is not a constructor.I looked back at an older version of the repo to find the original Coffeescript source file: https://github.com/CodeByZach/pace/blob/v1.2.0/pace.coffee. I believe that the error handling in this file was just poorly written - they've used
catch NoTargetError
, and I believe the intention here is that only NoTargetError errors should be caught. But the resulting compiled javascript code is:I've re-written those catch blocks as:
This means that all errors, including NoTargetError, will get caught and suppressed - the same behaviour as before. But the code no longer reassigns NoTargetError.
The original commit introducing NoTargetError and the catch block is here: db58761