Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wojtekmaj opened this issue Dec 12, 2023 · 9 comments
Assignees
Labels
bug Something isn't working P2

Comments

@wojtekmaj
Copy link

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 ejizba transferred this issue from Azure/azure-functions-core-tools Dec 13, 2023
@ejizba
Copy link
Contributor

ejizba commented Dec 13, 2023

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
Copy link
Author

wojtekmaj commented Dec 13, 2023

@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
Copy link
Contributor

ejizba commented Dec 13, 2023

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
Copy link
Member

I have just merged two PRs that should resolve this issue: Azure/azure-functions-nodejs-worker#732 and #220.

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

@sladkoff
Copy link

sladkoff commented May 7, 2024

@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
Copy link
Contributor

ejizba commented May 7, 2024

@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
Copy link

We're seeing a TypeError in this updated code that causes an unhandled promise rejection. Details in the PR: Azure/azure-functions-nodejs-worker#732 (comment).

@castrodd
Copy link
Member

This PR should have fixed this issue: Azure/azure-functions-nodejs-worker#750

@earloc
Copy link

earloc commented Aug 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2
Projects
None yet
Development

No branches or pull requests

6 participants