utilities icon indicating copy to clipboard operation
utilities copied to clipboard

bug: @sapphire/string-store may generate invalid custom ids

Open Jiralite opened this issue 8 months ago • 3 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Description of the bug

@sapphire/string-store may generate invalid ids. The following is an example:

enum CustomId {
  User = 0,
}

const store = new SchemaStore().add(
  new Schema(CustomId.User).string("username").snowflake("userId")
);

store.serialize(CustomId.User, { username: "Terra", userId: "1071822091814441000" });

This serialises to: �敔牲⡡А莅�

Creating a message in a channel will result in an internal server error and responding to an interaction with this custom id will immediately result in an unknown interaction.

Steps To Reproduce

Using discord.js 15.0.0-dev.1745021572-92e07c8f7:

import { Schema, SchemaStore } from "@sapphire/string-store";
import {
  Client,
  TextChannel,
  ComponentType,
  ButtonStyle,
  GatewayIntentBits,
  Events,
} from "discord.js";

const client = new Client({ intents: GatewayIntentBits.Guilds });

enum CustomId {
  User = 0,
}

const store = new SchemaStore().add(
  new Schema(CustomId.User).string("username").snowflake("userId")
);

client.on(Events.ClientReady, async () => {
  (client.channels.cache.get(CHANNEL_ID) as TextChannel).send({
    components: [
      {
        type: ComponentType.ActionRow,
        components: [
          {
            type: ComponentType.Button,
            style: ButtonStyle.Primary,
            label: "test",
            customId: store
              .serialize(CustomId.User, {
                username: "Terra",
                userId: "1071822091814441000",
              })
              .toString(),
          },
        ],
      },
    ],
  });
});

void client.login(DISCORD_TOKEN);

Expected behavior

The message should be created or the interaction should be responded to.

Screenshots

No response

Additional context

No response

System Info

System:
  OS: macOS 15.4.1
  CPU: (12) arm64 Apple M3 Pro
  Memory: 370.16 MB / 36.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 22.13.1 - /opt/homebrew/opt/node@22/bin/node
  Yarn: 1.22.22 - /opt/homebrew/bin/yarn
  npm: 10.9.2 - /opt/homebrew/opt/node@22/bin/npm
  pnpm: 9.12.3 - /opt/homebrew/bin/pnpm
  bun: 1.2.10 - ~/.bun/bin/bun
Browsers:
  Safari: 18.4

Jiralite avatar Apr 29 '25 09:04 Jiralite

If this is a 500, isn't that more on Discord than string-store to fix?

vladfrangu avatar Apr 29 '25 10:04 vladfrangu

I think this may be related: https://github.com/discord/discord-api-docs/issues/6561#issuecomment-1839512039

Jiralite avatar Apr 29 '25 10:04 Jiralite

What's the likelihood of a character falling in a non representable range? Trying to make heavy use of the library, and I hope to not get these issues.

Amgelo563 avatar Apr 30 '25 16:04 Amgelo563