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

Error [ERR_INTERNAL_ASSERTION]: TypeError [ERR_INVALID_THIS]: Value of "this" must be of type EventTarget #46323

Open
buu700 opened this issue Jan 23, 2023 · 4 comments

Comments

@buu700
Copy link

buu700 commented Jan 23, 2023

Version

v18.13.0

Platform

Linux ce9205dbff40 5.10.76-linuxkit #1 SMP PREEMPT Mon Nov 8 11:22:26 UTC 2021 aarch64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

import {Storage} from '@google-cloud/storage';
const storage = new Storage(...).bucket(...);
await storage.file(...).save(...);

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

Consistently.

Edit: I also confirmed that downgrading to Node 18.12.1 resolves the issue.

What is the expected behavior?

Function should succeed with no errors.

What do you see instead?

Error [ERR_INTERNAL_ASSERTION]: Error [ERR_INTERNAL_ASSERTION]: TypeError [ERR_INVALID_THIS]: Value of "this" must be of type EventTarget
    at new NodeError (node:internal/errors:400:5)
    at [nodejs.util.inspect.custom] (node:internal/event_target:758:13)
    at formatValue (node:internal/util/inspect:806:19)
    at formatProperty (node:internal/util/inspect:1920:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1920:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at inspect (node:internal/util/inspect:365:10)
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

Additional information

Related issue: googleapis/nodejs-storage#2133

@jasnell
Copy link
Member

jasnell commented Jan 23, 2023

I suspect that this is a problem with how nodejs-storage or another dependency is working. To help verify that, however, please expand the length of the stack trace using Error.stackTraceLimit = Infinity;. I want to see exactly from where in nodejs-storage the error is eminating.

@buu700
Copy link
Author

buu700 commented Jan 24, 2023

That helped add a lot of clarity to this, thanks @jasnell!

After making that change:

Error [ERR_INTERNAL_ASSERTION]: Error [ERR_INTERNAL_ASSERTION]: TypeError [ERR_INVALID_THIS]: Value of "this" must be of type EventTarget
    at new NodeError (node:internal/errors:400:5)
    at [nodejs.util.inspect.custom] (node:internal/event_target:758:13)
    at formatValue (node:internal/util/inspect:806:19)
    at formatProperty (node:internal/util/inspect:1920:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1920:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at inspect (node:internal/util/inspect:365:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2273:40)
    at formatWithOptions (node:internal/util/inspect:2135:10)
    at console.value (node:internal/console/constructor:349:14)
    at console.warn (node:internal/console/constructor:382:61)
    at console.<computed> [as error] (/cyph/shared/node_modules/@cyph/sdk/dist/sdk.cjs:1:5409867)
    at certSign (file:///cyph/commands/certsignlegacy.js:477:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

The indicated line 477 from my code is console.error(err); within a catch block. After removing the try-catch, the output becomes:

TypeError: RequestInit: duplex option is required when sending a body.
    at Object.fetch (node:internal/deps/undici/undici:14062:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  config: {
    method: 'PUT',
    url: 'https://storage.googleapis.com/upload/storage/v1/b/[redacted]',
    headers: {
      'x-goog-api-client': 'gl-node/18.13.0 gccl/6.9.0 gccl-invocation-id/[redacted]',
      'Content-Range': 'bytes 0-*/*',
      Authorization: 'Bearer [redacted]',
      Accept: 'application/json'
    },
    body: <ref *1> Readable {
      _readableState: ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: BufferList { head: null, tail: null, length: 0 },
        length: 0,
        pipes: [],
        flowing: false,
        ended: false,
        endEmitted: false,
        reading: true,
        constructed: true,
        sync: false,
        needReadable: true,
        emittedReadable: false,
        readableListening: true,
        resumeScheduled: false,
        errorEmitted: false,
        emitClose: true,
        autoDestroy: true,
        destroyed: false,
        errored: null,
        closed: false,
        closeEmitted: false,
        defaultEncoding: 'utf8',
        awaitDrainWriters: null,
        multiAwaitDrain: false,
        readingMore: false,
        dataEmitted: true,
        decoder: null,
        encoding: null,
        [Symbol(kPaused)]: null
      },
      _read: [AsyncFunction: read],
      _events: [Object: null prototype] {
        readable: [Function (anonymous)],
        end: [Function (anonymous)],
        finish: [Function (anonymous)],
        error: [Function (anonymous)],
        close: [Function (anonymous)]
      },
      _eventsCount: 5,
      _maxListeners: undefined,
      __zone_symbol__readablefalse: [
        ZoneTask {
          _zone: Zone {
            _parent: null,
            _name: '<root>',
            _properties: {},
            _zoneDelegate: [_ZoneDelegate]
          },
          runCount: 2,
          _zoneDelegates: [],
          _state: 'scheduled',
          type: 'eventTask',
          source: 'Readable.addListener:readable',
          data: undefined,
          scheduleFn: [Function: customScheduleNonGlobal],
          cancelFn: [Function: customCancelNonGlobal],
          callback: [Function: next],
          invoke: [Function (anonymous)],
          options: undefined,
          target: [Circular *1],
          capture: false,
          eventName: 'readable'
        }
      ],
      __zone_symbol__endfalse: [
        ZoneTask {
          _zone: Zone {
            _parent: null,
            _name: '<root>',
            _properties: {},
            _zoneDelegate: [_ZoneDelegate]
          },
          runCount: 0,
          _zoneDelegates: [],
          _state: 'scheduled',
          type: 'eventTask',
          source: 'Readable.addListener:end',
          data: undefined,
          scheduleFn: [Function: customScheduleNonGlobal],
          cancelFn: [Function: customCancelNonGlobal],
          callback: [Function: onend],
          invoke: [Function (anonymous)],
          options: undefined,
          target: [Circular *1],
          capture: false,
          eventName: 'end'
        }
      ],
      __zone_symbol__finishfalse: [
        ZoneTask {
          _zone: Zone {
            _parent: null,
            _name: '<root>',
            _properties: {},
            _zoneDelegate: [_ZoneDelegate]
          },
          runCount: 0,
          _zoneDelegates: [],
          _state: 'scheduled',
          type: 'eventTask',
          source: 'Readable.addListener:finish',
          data: undefined,
          scheduleFn: [Function: customScheduleNonGlobal],
          cancelFn: [Function: customCancelNonGlobal],
          callback: [Function: onfinish],
          invoke: [Function (anonymous)],
          options: undefined,
          target: [Circular *1],
          capture: false,
          eventName: 'finish'
        }
      ],
      __zone_symbol__errorfalse: [
        ZoneTask {
          _zone: Zone {
            _parent: null,
            _name: '<root>',
            _properties: {},
            _zoneDelegate: [_ZoneDelegate]
          },
          runCount: 0,
          _zoneDelegates: [],
          _state: 'scheduled',
          type: 'eventTask',
          source: 'Readable.addListener:error',
          data: undefined,
          scheduleFn: [Function: customScheduleNonGlobal],
          cancelFn: [Function: customCancelNonGlobal],
          callback: [Function: onerror],
          invoke: [Function (anonymous)],
          options: undefined,
          target: [Circular *1],
          capture: false,
          eventName: 'error'
        }
      ],
      __zone_symbol__closefalse: [
        ZoneTask {
          _zone: Zone {
            _parent: null,
            _name: '<root>',
            _properties: {},
            _zoneDelegate: [_ZoneDelegate]
          },
          runCount: 0,
          _zoneDelegates: [],
          _state: 'scheduled',
          type: 'eventTask',
          source: 'Readable.addListener:close',
          data: undefined,
          scheduleFn: [Function: customScheduleNonGlobal],
          cancelFn: [Function: customCancelNonGlobal],
          callback: [Function: onclose],
          invoke: [Function (anonymous)],
          options: undefined,
          target: [Circular *1],
          capture: false,
          eventName: 'close'
        }
      ],
      [Symbol(kCapture)]: false
    },
    signal: AbortSignal {},
    validateStatus: [Function (anonymous)],
    paramsSerializer: [Function: paramsSerializer],
    responseType: 'json'
  }
}

So the error itself may be a bug in either Node or @google-cloud/storage, but the console.error failure would be a Node bug either way.

@mscdex
Copy link
Contributor

mscdex commented Jan 24, 2023

See #46221 for the RequestInit error.

@Hakeemmidan
Copy link

I got this error when I was calling console.log() on the request object in a Next JS version 13.4.4 API endpoint file.

Calling JOSN.stringify() on the request object fixed it.

So changed from

console.log('@@@@@', request)

to

console.log('@@@@@', JSON.stringify(request))

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

4 participants