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

ERR_INTERNAL_ASSERTION from console.log(), TypeError: Converting circular structure to JSON #55539

Closed
ledlamp opened this issue Oct 25, 2024 · 6 comments · Fixed by #55544
Closed
Labels
confirmed-bug Issues with confirmed bugs. console Issues and PRs related to the console subsystem. util Issues and PRs related to the built-in util module.

Comments

@ledlamp
Copy link

ledlamp commented Oct 25, 2024

Version

v20.18.0, v23.1.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

No response

What steps will reproduce the bug?

import {Bot} from "@skyware/bot";

var bot = new Bot({
	emitEvents: false,
	emitChatEvents: true
});
await bot.login({
	identifier: "...",
	password: "..."
});

bot.on("message", async message => {
	console.log(message);
});

Then send chat message to the bot

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

100%, I cannot console.log() an object from someone's library.

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

Usually console.log() can log absolutely anything and will never error, circular references would just display [Circular].

What do you see instead?

node:internal/assert:20
  throw new ERR_INTERNAL_ASSERTION(message);
        ^

Error [ERR_INTERNAL_ASSERTION]: Error [ERR_INTERNAL_ASSERTION]: Error [ERR_INTERNAL_ASSERTION]: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Bot'
    |     property 'chatEventEmitter' -> object with constructor 'BotChatEmitter'
    --- property 'bot' closes the circle
    at JSON.stringify (<anonymous>)
    at get [Symbol.toStringTag] (file:///C:/Users/me/Desktop/bskychatbot/node_modules/quick-lru/index.js:291:15)
    at formatRaw (node:internal/util/inspect:857:18)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841: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

    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1557:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841: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

    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1557:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
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 Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1557:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1557:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1557:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946: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 handleMaxCallStackSize (node:internal/util/inspect:1557:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946: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 formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at inspect (node:internal/util/inspect:365:10)
    at inspect (node:internal/util/inspect:365:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2304:40)
    at formatWithOptions (node:internal/util/inspect:2166: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

    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1557:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at inspect (node:internal/util/inspect:365:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2304:40)
    at formatWithOptions (node:internal/util/inspect:2166:10)
    at console.value (node:internal/console/constructor:348:14)
    at console.log (node:internal/console/constructor:385:61)
    at Bot.<anonymous> (file:///C:/Users/me/Desktop/bskychatbot/index.mjs:14:10) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Node.js v20.18.0

Additional information

No response

@RedYetiDev
Copy link
Member

Hi! Can you provide a minimal reproduction without the external library?

@ledlamp
Copy link
Author

ledlamp commented Oct 25, 2024

No, I don't know how to.

@RedYetiDev
Copy link
Member

RedYetiDev commented Oct 25, 2024

Unfortunately, we can't reproduce as this requires API tokens and such, do you happen to have a reproduction (even if it's not minimal) without the login process?

@RedYetiDev RedYetiDev added console Issues and PRs related to the console subsystem. util Issues and PRs related to the built-in util module. labels Oct 25, 2024
@ledlamp
Copy link
Author

ledlamp commented Oct 25, 2024

I tried without login but then it did not trigger the bug.

import {Bot, ChatMessage} from "@skyware/bot";
var bot = new Bot();
var message = new ChatMessage({text: "asdf", sender: {did: "did:plc:u4gngygg2w5egsigxu5g7byu"}}, bot);
console.log(message);
$ node bug.mjs 
ChatMessage {
  bot: <ref *1> Bot {
    _events: [Object: null prototype] {},
    _eventsCount: 0,
    _maxListeners: undefined,
    agent: RateLimitedAgent {
      handle: [Function: bound handle] AsyncFunction,
      proxy: undefined,
      limiter: [RateLimitThreshold],
      labelers: [Set]
    },
    handler: CredentialManager {
      serviceUrl: 'https://bsky.social',
      fetch: [Function: fetch]
    },
    cache: {
      profiles: QuickLRU(0) [[]] {},
      posts: QuickLRU(0) [[]] {},
      lists: QuickLRU(0) [[]] {},
      feeds: QuickLRU(0) [[]] {},
      labelers: QuickLRU(0) [[]] {},
      starterPacks: QuickLRU(0) [[]] {},
      conversations: QuickLRU(0) [[]] {}
    },
    eventEmitter: BotEventEmitter {
      _events: [Object: null prototype],
      _eventsCount: 9,
      _maxListeners: undefined,
      bot: [Circular *1],
      strategy: 'polling',
      pollingInterval: 5,
      lastSeen: 2024-10-25T22:49:04.592Z,
      pollingController: AbortController {},
      firehose: undefined,
      jetstream: undefined,
      emitting: true,
      [Symbol(shapeMode)]: false,
      [Symbol(kCapture)]: false
    },
    chatEventEmitter: undefined,
    chatProxy: undefined,
    langs: [ 'en' ],
    profile: undefined,
    [Symbol(shapeMode)]: false,
    [Symbol(kCapture)]: false
  },
  id: undefined,
  conversationId: undefined,
  senderDid: 'did:plc:u4gngygg2w5egsigxu5g7byu',
  sentAt: undefined,
  sender: undefined,
  conversation: undefined,
  text: 'asdf',
  facets: undefined,
  embed: undefined
}

This code triggers the bug without any extra steps, but requires password.

import {Bot} from "@skyware/bot";

var bot = new Bot();
await bot.login({
	identifier: "testeststet.bsky.social",
	password: "..."
});

var conv = await bot.getConversationForMembers(["did:plc:u4gngygg2w5egsigxu5g7byu"]);
var message = await conv.sendMessage({text: "test"});

console.log(message);
$ node bug.mjs 
node:internal/assert:20
  throw new ERR_INTERNAL_ASSERTION(message);
        ^

Error [ERR_INTERNAL_ASSERTION]: Error [ERR_INTERNAL_ASSERTION]: Error [ERR_INTERNAL_ASSERTION]: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Bot'
    |     property 'eventEmitter' -> object with constructor 'BotEventEmitter'
    --- property 'bot' closes the circle
    at JSON.stringify (<anonymous>)
    at get [Symbol.toStringTag] (file:///home/ubuntu/bskychatbot/node_modules/quick-lru/index.js:291:15)
    at formatRaw (node:internal/util/inspect:857:18)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841: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

    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1557:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946:11)
    at formatRaw (node:internal/util/inspect:1055:9)
    at formatValue (node:internal/util/inspect:841: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

    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1557:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at formatProperty (node:internal/util/inspect:1946: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:2304:40)
    at formatWithOptions (node:internal/util/inspect:2166: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

    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1557:10)
    at formatRaw (node:internal/util/inspect:1063:12)
    at formatValue (node:internal/util/inspect:841:10)
    at inspect (node:internal/util/inspect:365:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2304:40)
    at formatWithOptions (node:internal/util/inspect:2166:10)
    at console.value (node:internal/console/constructor:348:14)
    at console.log (node:internal/console/constructor:385:61)
    at file:///home/ubuntu/bskychatbot/bug.mjs:12:9 {
  code: 'ERR_INTERNAL_ASSERTION'
}

Node.js v20.18.0

Perhaps I can give you password to test account privately?

@RedYetiDev
Copy link
Member

RedYetiDev commented Oct 25, 2024

No. I would prefer not to transfer information privately. Rather, someone will see this and help to provide a minimal reproduction. I'll also try myself.

Hopefully, in a few days, we'll have a minimal reproduction.

@cjihrig
Copy link
Contributor

cjihrig commented Oct 26, 2024

This seems to reproduce the issue:

const { inspect } = require('node:util');
const y = {
  get [Symbol.toStringTag]() {
    return JSON.stringify(this);
  }
};
const x = { y };
y.x = x;
inspect(x);

You can get an even simpler repro stack trace if you inspect(y) instead of x.

It's because this line triggers a getter that throws in the quick-lru module. Independent of any cycle detection, this doesn't seem to be handled correctly at the moment.

@RedYetiDev RedYetiDev added the confirmed-bug Issues with confirmed bugs. label Oct 26, 2024
aduh95 pushed a commit that referenced this issue Nov 6, 2024
PR-URL: #55544
Fixes: #55539
Reviewed-By: James M Snell <jasnell@gmail.com>
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com>
aduh95 pushed a commit that referenced this issue Nov 6, 2024
PR-URL: #55544
Fixes: #55539
Reviewed-By: James M Snell <jasnell@gmail.com>
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com>
aduh95 pushed a commit that referenced this issue Nov 6, 2024
PR-URL: #55544
Fixes: #55539
Reviewed-By: James M Snell <jasnell@gmail.com>
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com>
tpoisseau pushed a commit to tpoisseau/node that referenced this issue Nov 21, 2024
PR-URL: nodejs#55544
Fixes: nodejs#55539
Reviewed-By: James M Snell <jasnell@gmail.com>
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com>
ruyadorno pushed a commit that referenced this issue Nov 27, 2024
PR-URL: #55544
Fixes: #55539
Reviewed-By: James M Snell <jasnell@gmail.com>
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com>
ruyadorno pushed a commit that referenced this issue Nov 27, 2024
PR-URL: #55544
Fixes: #55539
Reviewed-By: James M Snell <jasnell@gmail.com>
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com>
ruyadorno pushed a commit that referenced this issue Nov 27, 2024
PR-URL: #55544
Fixes: #55539
Reviewed-By: James M Snell <jasnell@gmail.com>
Co-Authored-By: Colin Ihrig <cjihrig@gmail.com>
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. console Issues and PRs related to the console subsystem. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants