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

bug: Error when getting output type of "require('discord.js')" #547

Closed
1 task done
BannerBomb opened this issue Apr 6, 2024 · 3 comments · Fixed by #573
Closed
1 task done

bug: Error when getting output type of "require('discord.js')" #547

BannerBomb opened this issue Apr 6, 2024 · 3 comments · Fixed by #573

Comments

@BannerBomb
Copy link

BannerBomb commented Apr 6, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

Only seems to happen when requiring discord.js and evaluating the output of it using the Type class. So I doubt you would want to fix it. Just thought I'd make a bug report just in case.

Example code includes

const { Type } = require('@sapphire/type');
const DJS = require('discord.js');
const output = new Type(DJS);
output.toString();

Will cause the error.

TypeError: Cannot read properties of null (reading 'name')
     at Function.resolve (/opt/stratobotelite/node_modules/@sapphire/type/src/lib/index.ts:152:2)
     at new Type (/opt/stratobotelite/node_modules/@sapphire/type/src/lib/index.ts:60:13)
     at _Type.addValue (/opt/stratobotelite/node_modules/@sapphire/type/src/lib/index.ts:102:25)
     at _Type.addEntry (/opt/stratobotelite/node_modules/@sapphire/type/src/lib/index.ts:112:30)
     at _Type.check (/opt/stratobotelite/node_modules/@sapphire/type/src/lib/index.ts:134:2)
     at _Type.toString (/opt/stratobotelite/node_modules/@sapphire/type/src/lib/index.ts:77:7)
     at Function.codeBlock (/opt/stratobotelite/src/frameworks/klasa/lib/util/util.js:41:42)
     at module.exports.run (/opt/stratobotelite/src/bot/commands/Admin/eval.js:138:23)
     at processTicksAndRejections (node:internal/process/task_queues:95:5)
     at async module.exports.runCommand (/opt/stratobotelite/src/bot/monitors/commandHandler.js:75:23)

Steps To Reproduce

const { Type } = require('@sapphire/type');
const DJS = require('discord.js');
const output = new Type(DJS);
output.toString();

Expected behavior

Wasn't expected to error.

Screenshots

image
image

Additional context

No response

System Info

System:
    OS: Linux 4.15 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (4) x64 Intel Core Processor (Haswell, no TSX)
    Memory: 6.34 GB / 7.60 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 21.7.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.5.0 - /usr/local/bin/npm
@favna
Copy link
Member

favna commented Apr 6, 2024

This is not the intended use case of this package. It's supposed to be used on a variable, not on a module. That said it is odd. We can look into it.

@BannerBomb
Copy link
Author

BannerBomb commented Apr 6, 2024

This is not the intended use case of this package. It's supposed to be used on a variable, not on a module. That said it is odd. We can look into it.

yeah, I just made a bug report because if it happens on something like this it may error in certain circumstances.

So I did a test and these are the modules that it errors on when trying to read them.

[
  [ 'SlashCommandBuilder', [Function: SlashCommandBuilder] ],
  [
    'SlashCommandChannelOption',
    [Function: SlashCommandChannelOption]
  ],
  [
    'SlashCommandIntegerOption',
    [Function: SlashCommandIntegerOption]
  ],
  [ 'SlashCommandNumberOption', [Function: SlashCommandNumberOption] ],
  [ 'SlashCommandStringOption', [Function: SlashCommandStringOption] ],
  [
    'SlashCommandSubcommandBuilder',
    [Function: SlashCommandSubcommandBuilder]
  ],
  [
    'SlashCommandSubcommandGroupBuilder',
    [Function: SlashCommandSubcommandGroupBuilder]
  ]
]

Found by doing

const { Type } = require('@sapphire/type');
const results = [];
const errors = [];
for (const [key, value] of Object.entries(require('discord.js'))) {
    try {
        results.push(new Type(value));
    } catch (error) {
        results.push(error);
        errors.push([key, value])
    }
}
console.log(errors);

As the above seems to have a "constructor" of null
image

@favna
Copy link
Member

favna commented Jul 11, 2024

Released in v2.5.1

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

Successfully merging a pull request may close this issue.

2 participants