Skip to content

Conversation

@fabb
Copy link

@fabb fabb commented Nov 14, 2021

Summary

  • fixes the e.replace is not a function error happening on production in Firefox during createInstance

in js, any object can be thrown. that is why the catch block error variable has type unknown in 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 is string | Error which 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 in internalLog -> format -> sprintf because sprintf is calling .replace on the message, which throws with e.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

@fabb fabb requested a review from a team as a code owner November 14, 2021 12:18
… in Firefox during createInstance

in js, any object can be thrown. that is why the `catch` block `error` variable has type `unknown` in 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 is `string | Error` which 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 in `internalLog -> format -> sprintf` because sprintf is calling `.replace` on the message, which throws with `e.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.

fixes optimizely#719
@fabb fabb force-pushed the bugfix/e.replace-is-not-a-function branch from 200d212 to 1418e83 Compare November 14, 2021 13:19
@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.138% when pulling 1418e83 on willhaben:bugfix/e.replace-is-not-a-function into f034de4 on optimizely:master.

@mikechu-optimizely
Copy link
Contributor

Woah. This has been out here a while. Sorry about that @fabb. Is it still relevant?

@fabb
Copy link
Author

fabb commented Aug 2, 2023

This has been fixed in optimizely/react-sdk#134 (comment)

@fabb fabb closed this Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

e.replace is not a function

3 participants