Fixes e.replace is not a function error
#720
Closed
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.
Summary
e.replace is not a functionerror happening on production in Firefox during createInstancein js, any object can be thrown. that is why the
catchblockerrorvariable has typeunknownin typescript. in optimizely, there are a few catch blocks where the error variable is directly logged as message. in the logger, the type of the public named logging functions isstring | Errorwhich is not correct since it could actually be any type. if it is an object that is not an instance of type Error, this will cause a throw ininternalLog -> format -> sprintfbecause sprintf is calling.replaceon the message, which throws withe.replace is not a function. we have seen this exact error a lot in production. so logging causes a throw which causes createInstance to fail, causing further issues.this PR fixes the issue by converting non-string and non-Error log messages to string first.
Test plan
Issues