{"id":"de205aac0c3124ef","repo":"knex/knex","slug":"a-name-must-be-specified-for-the-generated-seed","errorCode":null,"errorMessage":"A name must be specified for the generated seed","messagePattern":"A name must be specified for the generated seed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/migrations/seed/Seeder.js","lineNumber":30,"sourceCode":"// the seeds.\nclass Seeder {\n  constructor(knex) {\n    this.knex = knex;\n    this.config = this.resolveConfig(knex.client.config.seeds);\n  }\n\n  // Runs seed files for the given environment.\n  async run(config) {\n    this.config = this.resolveConfig(config);\n    const files = await this.config.seedSource.getSeeds(this.config);\n    return this._runSeeds(files);\n  }\n\n  // Creates a new seed file, with a given name.\n  async make(name, config) {\n    this.config = this.resolveConfig(config);\n    if (!name)\n      throw new Error('A name must be specified for the generated seed');\n    await this._ensureFolder(config);\n    const seedPath = await this._writeNewSeed(name);\n    return seedPath;\n  }\n\n  // Ensures a folder for the seeds exist, dependent on the\n  // seed config settings.\n  _ensureFolder() {\n    const dirs = this.config.seedSource._getConfigDirectories(\n      this.config.logger\n    );\n    const promises = dirs.map(ensureDirectoryExists);\n    return Promise.all(promises);\n  }\n\n  // Run seed files, in sequence.\n  async _runSeeds(seeds) {\n    for (const seed of seeds) {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/knex/knex/blob/e25d54bcb707714a17f5a5744eba5c4246bb4d1d/lib/migrations/seed/Seeder.js#L12-L48","documentation":"Seeder.make(name, config) requires a non-empty name to generate the seed file; if name is falsy (undefined, null, empty string) it throws before touching the filesystem. This is a hard guard at the top of the make method so generated seed files always have a meaningful filename.","triggerScenarios":"Calling knex.seed.make() with no arguments; passing an empty string or undefined; building the name dynamically from a variable that resolved to undefined.","commonSituations":"CLI script that forgot the name argument; programmatic seed generation where the name comes from a config that's missing; refactoring that renamed a variable to undefined.","solutions":["Pass a descriptive non-empty name: knex.seed.make('seed-admin-users').","If generating the name dynamically, default it: `await knex.seed.make(name || `seed-${Date.now()}`)`.","Validate the name is a non-empty string before calling make()."],"exampleFix":"// before\nawait knex.seed.make();\n\n// after\nawait knex.seed.make('admin-users');","handlingStrategy":"validation","validationCode":"if (!name || typeof name !== 'string') throw new Error('seed name required');\nawait knex.seed.make(name);","typeGuard":"function isSeedName(name) { return typeof name === 'string' && name.trim().length > 0; }","tryCatchPattern":null,"preventionTips":["Always pass a descriptive name to knex.seed.make().","Default a computed name with a fallback so it can't be empty.","Validate the name is a non-empty string before calling."],"tags":["seeds","validation"],"analyzedSha":"e25d54bcb707714a17f5a5744eba5c4246bb4d1d","analyzedAt":"2026-08-03T18:35:32.148Z","schemaVersion":2}