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

Cannot read private member #context from an object whose class did not declare it #50891

Closed
KrayzeeKev opened this issue Nov 24, 2023 · 3 comments

Comments

@KrayzeeKev
Copy link
Contributor

KrayzeeKev commented Nov 24, 2023

Version

v20.10.0

Platform

Oracle Enterprise Linux 7

Subsystem

lib/internal/url.js ?

What steps will reproduce the bug?

This occurs when @hapi/wreck is attempting to process a request. The error string above does NOT appear in the source of wreck or anything else in any node_modules directory.

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

Should not fail.

What do you see instead?

err: TypeError: Client request error: Cannot read private member #context from an object whose class did not declare it

Additional information

I added a console.log(new Error().stack) into @hapi/wreck/lib/index.js to try work out where the error came from. Trace below:

Error
    at ClientRequest.onError (/opt/APP/node_modules/@hapi/wreck/lib/index.js:192:13)
    at Object.onceWrapper (node:events:629:26)
    at ClientRequest.emit (node:events:514:28)
    at _destroy (node:_http_client:875:13)
    at onSocketNT (node:_http_client:895:5)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
2023-11-20T09:41:01+11:00 [ERROR] - Failed to Get Token - err: TypeError: Client request error: Cannot read private member #context from an object whose class did not declare it

The string context does not appear in @hapi/wreck at all.
The string #context does not appear anywhere in my source or node_modules.
The error message does not appear in that form ANYWHERE I can find in files on my machine. There are several instances WITHOUT the identifier but it must be generated here:
deps/v8/src/common/message-template.h:493: "Cannot read private member % from an object whose class did not declare "
I am guessing this is caused by some inbuilt JavaScript in Node itself? In fact, I'm guessing lib/internal/url.js based on a grep of the source for #context.
This does NOT happen in v18.18.2 and earlier. I switched to v20.9 when it went LTS. Issue persists in v20.10. Have not tried any v20 before v20.9
The version of our source and of node_modules is unchanged between v18.18.2 and v20 (just running new node manually on same deployment tree fails).

@KrayzeeKev
Copy link
Contributor Author

This issue goes all the way back to v20.0.0

@KrayzeeKev
Copy link
Contributor Author

Have determined this is the result of @hapi/hoek/lib/clone.js which copies an https-proxy-agent options object which contains a parsed URL. This code reproduces the effect:

const url = new URL('http://proxy:443');
const proto = Object.getPrototypeOf(url);
const copy = Object.create(proto);
console.log(copy);

The clone util then goes on to copy all the properties but that's not even necessary. Just the raw object throws the error

/usr/local/node-v20.10.0-linux-x64/bin/node k.js
node:internal/url:844
    return this.#context.href;
                ^

TypeError: Cannot read private member #context from an object whose class did not declare it
    at get href [as href] (node:internal/url:844:17)
    at [nodejs.util.inspect.custom] (node:internal/url:785:21)
    at formatValue (node:internal/util/inspect:805:19)
    at inspect (node:internal/util/inspect:364:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2298:40)
    at formatWithOptions (node:internal/util/inspect:2160:10)
    at console.value (node:internal/console/constructor:342:14)
    at console.log (node:internal/console/constructor:379:61)
    at Object.<anonymous> (/opt/APP/k.js:4:9)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)

Node.js v20.10.0

@KrayzeeKev
Copy link
Contributor Author

Closing as this is clearly an issue with @Hapi deep cloning and Node is behaving as designed.

@KrayzeeKev KrayzeeKev closed this as not planned Won't fix, can't repro, duplicate, stale Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant