Azure / azure-functions-nodejs-worker

The Node.js worker for the Azure Functions runtime - https://functions.azure.com
MIT License
107 stars 44 forks source link

Check errors are writable #732

Closed castrodd closed 9 months ago

castrodd commented 9 months ago

This PR addresses an issue raised in the Library repo: https://github.com/Azure/azure-functions-nodejs-library/issues/205.

In short, a customer was using a package that extends the Error class and renders the message property read-only.

This caused an error in FunctionLoadHandler.ts when we attempt to write our own custom error message:

error.message = `Worker was unable to load function ${metadata.name}: '${error.message}'`;

Our function ensureErrorType was not filtering out these read-only errors because instanceof Error was in fact true. Therefore, we simply returned these errors without any modification, assuming they were in fact instances of Error, not a subclass with different behavior.

This PR introduces an explicit check to ensure that we are not passing along read-only objects and hitting this exception:

Exception: Cannot set property message of [object Object] which has only a getter