{"record":{"id":"2acb2c8167b654a1","repo":"discordjs/discord.js","slug":"clientinvalidoption-2acb2c","errorCode":"ClientInvalidOption","errorMessage":"ClientInvalidOption: File, specified.","messagePattern":"ClientInvalidOption: File, specified\\.","errorType":"error_code","errorClass":"DiscordjsError","httpStatus":null,"severity":"error","filePath":"packages/discord.js/src/sharding/ShardingManager.js","lineNumber":74,"sourceCode":"    super();\n    const _options = {\n      totalShards: 'auto',\n      mode: 'process',\n      respawn: true,\n      silent: false,\n      shardArgs: [],\n      execArgv: [],\n      token: process.env.DISCORD_TOKEN,\n      ...options,\n    };\n\n    /**\n     * Path to the shard script file\n     *\n     * @type {string}\n     */\n    this.file = file;\n    if (!file) throw new DiscordjsError(ErrorCodes.ClientInvalidOption, 'File', 'specified.');\n    if (!path.isAbsolute(file)) this.file = path.resolve(process.cwd(), file);\n    // eslint-disable-next-line n/no-sync\n    const stats = fs.statSync(this.file);\n    if (!stats.isFile()) throw new DiscordjsError(ErrorCodes.ClientInvalidOption, 'File', 'a file');\n\n    /**\n     * List of shards this sharding manager spawns\n     *\n     * @type {string|number[]}\n     */\n    this.shardList = _options.shardList ?? 'auto';\n    if (this.shardList !== 'auto') {\n      if (!Array.isArray(this.shardList)) {\n        throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'shardList', 'an array.');\n      }\n\n      this.shardList = [...new Set(this.shardList)];\n      if (this.shardList.length < 1) {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/discord.js/src/sharding/ShardingManager.js#L56-L92","documentation":"ShardingManager requires a path to the shard script file as its first constructor argument. If the value is falsy (empty string, undefined, null), the constructor throws ClientInvalidOption('File', 'specified.') immediately at ShardingManager.js:74, before any filesystem access.","triggerScenarios":"Calling new ShardingManager(''), new ShardingManager(), or passing a variable that resolves to undefined/null (e.g. process.env.SHARD_FILE not set) as the file argument.","commonSituations":"Config read from env or JSON where the shard file key is missing; refactored code where the file path constant was deleted; passing a value from an optional CLI argument without a default.","solutions":["Pass the absolute or relative path to your shard script as the first constructor argument","Ensure the config/env value supplying the path is defined before constructing ShardingManager","Add a startup check that fails early with a clear message if the path is missing"],"exampleFix":"// before\nnew ShardingManager(process.env.SHARD_FILE);\n// after\nif (!process.env.SHARD_FILE) throw new Error('SHARD_FILE env var is required');\nconst manager = new ShardingManager(process.env.SHARD_FILE);","handlingStrategy":"validation","validationCode":"const file = process.env.SHARD_FILE;\nif (!file) throw new Error('Shard file path is required');\nconst manager = new ShardingManager(file);","typeGuard":"const hasFile = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  const manager = new ShardingManager(file);\n} catch (err) {\n  if (err.name === 'DiscordjsTypeError' && err.message.includes('File')) {\n    console.error('Invalid shard file option:', err.message);\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Always pass path.join(__dirname, 'shard.js') so the path is deterministic","Fail fast at startup if env/config supplying the path is missing","Add a unit test constructing ShardingManager with your real config"],"tags":["discord-js","sharding","argument-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}