Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mishandling of message parameter in runtime.newErrorObject
runtime.newErrorObject is used to implement the Error constructor, and as such it takes input from JavaScript via calls like `new Error('xxx')`. The actual underlying error information is stored in an ottoError object, which is constructed using newError. newError takes a couple of mandatory arguments, then treats the remaining parameters (collected as `in ...interface{}`) as a printf-style format string and parameter list, which it uses to populate the message field of the returned ottoError object. newErrorObject was passing the message parameter from the Error function exposed to JavaScript directly through to newError as the first optional parameter, which led to it being treated as a format string, which resulted in any code like `throw new Error('%s')` behaving incorrectly, with the resultant error having a message like "%!s(MISSING)". This change fixes this behaviour in the least intrusive way I could find, and adds some tests to make sure it doesn't come back. The logic for newErrorObject and newErrorObjectError are very similar, so it was tempting to try to merge them, but it appears they're used in somewhat fragile ways with very little test coverage so I'll leave that as a problem for another day.
- Loading branch information