Azure / azure-functions-nodejs-library

The Node.js framework for Azure Functions
https://www.npmjs.com/package/@azure/functions
MIT License
58 stars 14 forks source link

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

Closed wojtekmaj closed 3 months ago

wojtekmaj commented 11 months ago

When attempting to run a function, which crashed on startup (for an unrelated reason), I got the following error:

[2023-12-12T12:41:34.171Z] Worker failed to load function: 'func-name' with functionId: '…'.
[2023-12-12T12:41:34.171Z] Result: Failure
[2023-12-12T12:41:34.171Z] Exception: Cannot set property message of [object Object] which has only a getter
[2023-12-12T12:41:34.171Z] Stack: TypeError: Cannot set property message of [object Object] which has only a getter
[2023-12-12T12:41:34.171Z]     at h.<anonymous> (/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5455/workers/node/dist/src/worker-bundle.js:2:33509)
[2023-12-12T12:41:34.171Z]     at Generator.throw (<anonymous>)
[2023-12-12T12:41:34.171Z]     at a (/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5455/workers/node/dist/src/worker-bundle.js:2:32342).

instead of the actual error message that got thrown by my function.

worker-bundle.js:2:33509 corresponds to this line:

t.message=`Worker was unable to load function ${r.name}: '${t.message}'`

so there's something wrong with the way errors are handled.

ejizba commented 11 months ago

Hi @wojtekmaj can you share your version of core tools and the "@azure/functions" npm package? If you have sample repro code, that would also be very helpful

wojtekmaj commented 11 months ago

@ejizba @azure/functions was at 3.5.1 in the project I could reproduce that in. I don't think that's relevant though. I can now see that what was thrown from my function was not Error, but ZodError from zod schema validation library. I believe ensureErrorType helper does not account for this. When "pure" Error is thrown the issue cannot be reproduced.

ejizba commented 11 months ago

Okay I think I understand what's happening here. The ZodError type apparently makes the "message" property read-only and doesn't let us change the message. We'll look into this. If you need a workaround in the meantime, you could probably catch the error yourself and either log it or convert it to a more normal error type that we can handle

castrodd commented 9 months ago

I have just merged two PRs that should resolve this issue: https://github.com/Azure/azure-functions-nodejs-worker/pull/732 and https://github.com/Azure/azure-functions-nodejs-library/pull/220.

When these changes are deployed, I will close out this issue.

sladkoff commented 6 months ago

@castrodd Is the fix available on Azure yet? We are experiencing a similar problem and I'm not able to find any information on the currently deployed function-host versions.

ejizba commented 6 months ago

@sladkoff It actually just started rolling out and should finish in the next couple weeks. At least for Node.js, you could check our github releases here. Of course, commenting on a specific issue is also probably one of the best ways to get this info 🙂 Btw, if you're on Windows consumption and want to test it out today, I believe the East Asia and West Central US regions already have the fix.

ryanbecker commented 6 months ago

We're seeing a TypeError in this updated code that causes an unhandled promise rejection. Details in the PR: https://github.com/Azure/azure-functions-nodejs-worker/pull/732#discussion_r1604141371.

castrodd commented 3 months ago

This PR should have fixed this issue: https://github.com/Azure/azure-functions-nodejs-worker/pull/750

earloc commented 3 months ago

Facing the exact same thing, which took me quite some time to figure out what actually was wrong. We´re using zod to parse/validate configuration, which sometimes happens in global context.

Azure Functions Core Tools Core Tools Version: 4.0.5907 Commit hash: N/A +807e89766a92b14fd07b9f0bc2bea1d8777ab209 (64-bit) Function Runtime Version: 4.834.3.22875

@azure/functions: 3.5.1

Is there any ETA, when this gets shipped? Currently working around by wrapping the causing logic in a try/catch and throwing a new Error (combined with a console.error, as the logic currently is out of a context).

I have prepared a simple repro here:

https://github.com/earloc/repros-azure-functions-nodejs-library