Skip to content

Error [ERR_INTERNAL_ASSERTION]: TypeError: Method height called on incompatible receiver #<Canvas> #39866

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

Closed
lynn2910 opened this issue Aug 24, 2021 · 9 comments
Labels
confirmed-bug Issues with confirmed bugs. util Issues and PRs related to the built-in util module.

Comments

@lynn2910
Copy link

lynn2910 commented Aug 24, 2021

Version

v16.7.0

Platform

Microsoft Windows NT 10.0.19043.0 x64

Subsystem

No response

What steps will reproduce the bug?

First, i have start a PowerShell terminal in visual studio code.

After, i run the command "npm i canvas" and i have this error from the command :

node:internal/errors:464
    ErrorCaptureStackTrace(err);

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

This error occurs as soon as I require the "canvas" module, but only with this module.

What is the expected behavior?

I should receive this when requesting the module :

{
  Canvas: [Function],
  Context2d: [Function],
  CanvasRenderingContext2D: [Function],
  CanvasGradient: [Function],
  CanvasPattern: [Function],
  Image: [Function],
  ImageData: [Function],
  PNGStream: [Function],
  PDFStream: [Function],
  JPEGStream: [Function],
  DOMMatrix: [Function],
  DOMPoint: [Function],
  registerFont: [Function],
  parseFont: [Function],
  createCanvas: [Function],
  createImageData: [Function],
  loadImage: [Function],
  backends: [Object],
  version: '2.8.0',
  cairoVersion: '1.17.4',
  jpegVersion: '8',
  gifVersion: '5.2.1',
  freetypeVersion: '2.10.4',
  rsvgVersion: '2.50.3',
  averageColor: [AsyncFunction]
}

What do you see instead?

I see this error :

node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_INTERNAL_ASSERTION]: Error [ERR_INTERNAL_ASSERTION]: Error [ERR_INTERNAL_ASSERTION]: TypeError: Method height called on incompatible receiver #<Canvas>
    at getOwnPropertyDescriptor (<anonymous>)
    at formatProperty (node:internal/util/inspect:1674:18)
    at formatRaw (node:internal/util/inspect:1004:9)
    at formatValue (node:internal/util/inspect:791:10)
    at formatProperty (node:internal/util/inspect:1679:11)
    at formatRaw (node:internal/util/inspect:1004:9)
    at formatValue (node:internal/util/inspect:791:10)
    at formatProperty (node:internal/util/inspect:1679:11)
    at formatRaw (node:internal/util/inspect:1004:9)
    at formatValue (node:internal/util/inspect:791:10)
    at Object.inspect (node:internal/util/inspect:338:10)
    at msgResponse (C:\Users\CEDRIC2005\code\eden\LanaPUBLIC\exe\cmd\dev\eval.js:42:108)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at new NodeError (node:internal/errors:371:5)
    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1368:10)
    at formatRaw (node:internal/util/inspect:1011:12)
    at formatValue (node:internal/util/inspect:791:10)
    at formatRaw (node:internal/util/inspect:1004:9)
    at formatProperty (node:internal/util/inspect:1679:11)
    at formatRaw (node:internal/util/inspect:1004:9)
    at formatValue (node:internal/util/inspect:791:10)
    at Object.inspect (node:internal/util/inspect:338:10)
    at getGoodLength (C:\Users\CEDRIC2005\code\eden\LanaPUBLIC\exe\cmd\dev\eval.js:31:65)
    at msgResponse (C:\Users\CEDRIC2005\code\eden\LanaPUBLIC\exe\cmd\dev\eval.js:42:108)
    at Object.exe (C:\Users\CEDRIC2005\code\eden\LanaPUBLIC\exe\cmd\dev\eval.js:59:7)
    at processTicksAndRejections (node:internal/process/task_queues:96: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

    at new NodeError (node:internal/errors:371:5)
    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1368:10)
    at formatRaw (node:internal/util/inspect:1011:12)
    at formatValue (node:internal/util/inspect:791:10)
    at formatProperty (node:internal/util/inspect:1679:11)
    at formatRaw (node:internal/util/inspect:1004:9)
    at formatValue (node:internal/util/inspect:791:10)
    at Object.inspect (node:internal/util/inspect:338:10)
    at getGoodLength (C:\Users\CEDRIC2005\code\eden\LanaPUBLIC\exe\cmd\dev\eval.js:31:65)
    at msgResponse (C:\Users\CEDRIC2005\code\eden\LanaPUBLIC\exe\cmd\dev\eval.js:42:108)
    at Object.exe (C:\Users\CEDRIC2005\code\eden\LanaPUBLIC\exe\cmd\dev\eval.js:59:7)
    at processTicksAndRejections (node:internal/process/task_queues:96: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

    at new NodeError (node:internal/errors:371:5)
    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1368:10)
    at formatRaw (node:internal/util/inspect:1011:12)
    at formatValue (node:internal/util/inspect:791:10)
    at Object.inspect (node:internal/util/inspect:338:10)
    at getGoodLength (C:\Users\CEDRIC2005\code\eden\LanaPUBLIC\exe\cmd\dev\eval.js:31:65)
    at msgResponse (C:\Users\CEDRIC2005\code\eden\LanaPUBLIC\exe\cmd\dev\eval.js:42:108)
    at Object.exe (C:\Users\CEDRIC2005\code\eden\LanaPUBLIC\exe\cmd\dev\eval.js:59:7)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Additional information

No response

Edit :

I see the require response with require("util").inspect(data).
But if i use the method JSON.stringify(data) or call a string after, no error occured.

// ENTRIES
JSON.stringify(require("canvas"), null, 2)

// OUTPUT
{
  "backends": {},
  "version": "2.8.0",
  "cairoVersion": "1.17.4",
  "jpegVersion": "8",
  "gifVersion": "5.2.1",
  "freetypeVersion": "2.10.4",
  "rsvgVersion": "2.50.3"
}

or

// ENTRIES
require("canvas"); "hello"

// OUTPUT
"hello"

this code is executed from the method eval

@Ayase-252
Copy link
Member

Thanks for bug reporting, could you provide a more precise description about how to repro the error? Does the error occur when installing canvas by npm/yarn or requiring it by require('canvas')?

I have tried on MacOS

const canvas = require("canvas")
const util = require('util')

console.log(util.inspect(canvas))
node index.js
{
  Canvas: [Function: Canvas] { _registerFont: [Function: _registerFont] },
  Context2d: [Function: CanvasRenderingContext2D],
  CanvasRenderingContext2D: [Function: CanvasRenderingContext2D],
  CanvasGradient: [Function: CanvasGradient],
  CanvasPattern: [Function: CanvasPattern],
  Image: [Function: Image] { MODE_IMAGE: 1, MODE_MIME: 2 },
  ImageData: [Function: ImageData],
  PNGStream: [Function: PNGStream],
  PDFStream: [Function: PDFStream],
  JPEGStream: [Function: JPEGStream],
  DOMMatrix: [Function: DOMMatrix] {
    fromMatrix: [Function (anonymous)],
    fromFloat32Array: [Function (anonymous)],
    fromFloat64Array: [Function (anonymous)]
  },
  DOMPoint: [Function: DOMPoint],
  registerFont: [Function: registerFont],
  parseFont: [Function (anonymous)],
  createCanvas: [Function: createCanvas],
  createImageData: [Function: createImageData],
  loadImage: [Function: loadImage],
  backends: {
    ImageBackend: [Function: ImageBackend],
    PdfBackend: [Function: PdfBackend],
    SvgBackend: [Function: SvgBackend]
  },
  version: '2.8.0',
  cairoVersion: '1.16.0',
  jpegVersion: '9d',
  gifVersion: '5.2.1',
  freetypeVersion: '2.10.4',
  rsvgVersion: '2.50.5'
}

It works as intented.

@lynn2910
Copy link
Author

lynn2910 commented Aug 25, 2021

The error occured when i requiring the module, the installation work properly.

my exact code is :

const code = message.content.slice(prefix.length+command.length+1); // this line work with the module discord.js
const res = await eval(code);
return require("util").inspect(res, { showHidden: true, color: false }); // the error is here

@targos targos added confirmed-bug Issues with confirmed bugs. util Issues and PRs related to the built-in util module. labels Aug 25, 2021
@targos
Copy link
Member

targos commented Aug 25, 2021

To reproduce the error:

const canvas = require('canvas')
Object.getOwnPropertyDescriptor(canvas.Canvas.prototype, 'width')
Object.getOwnPropertyDescriptor(canvas.Canvas.prototype, 'width')
       ^

TypeError: Method width called on incompatible receiver #<Canvas>
    at Function.getOwnPropertyDescriptor (<anonymous>)

@targos
Copy link
Member

targos commented Aug 25, 2021

@nodejs/util

@Ayase-252
Copy link
Member

Access to getters/setters on prototype of Canvas was forbiden intentionally in Automattic/node-canvas#808.

It means that ObjectGetOwnPropertyDescriptor may not be guaranteed to work?

desc = desc || ObjectGetOwnPropertyDescriptor(value, key) ||

Refs: Automattic/node-canvas#1460

@targos
Copy link
Member

targos commented Aug 27, 2021

@Ayase-252 it seems to be the issue, but I'm a bit surprised by that.

I don't see in the spec where Object.getOwnPropertyDescriptor could throw an error in this situation.

@nodejs/v8

@victorgomes
Copy link

victorgomes commented Aug 27, 2021

Object.getOwnPropertyDescriptor in V8 will access the getter here: https://source.chromium.org/chromium/chromium/src/+/main:v8/src/objects/js-objects.cc;drc=441d37da23011674ee4975b0cb738733f8e72ec9;l=1721
If it fails, it will return the exception.

I guess that's the correct behaviour according to the spec:

6. If Desc has a [[Get]] field, then
a. Perform ! CreateDataPropertyOrThrow(obj, "get", Desc.[[Get]]).

@BridgeAR
Copy link
Member

How should we handle these cases in general? This is not the first time something like that has come up and it's not specific to logging. We could use an internal getOwnPropertyDescriptor() function that catches the error and that returns a object in the expected form with the value e.g., being set to null or undefined?

@BridgeAR
Copy link
Member

By now I wonder if we really want to special handle this. I don't really think so as it is something that comes from an implementation that does things in a way that V8 is not able to handle and I guess that could happen in multiple places for lots of reasons. If someone disagrees, please leave a comment or reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

5 participants