{"record":{"id":"6425547bd0a8d7c9","repo":"vercel/turborepo","slug":"plop-error-running-generator","errorCode":"plop_error_running_generator","errorMessage":"Failed to run generator","messagePattern":"Failed to run generator","errorType":"exception","errorClass":"GeneratorError","httpStatus":null,"severity":"error","filePath":"packages/turbo-gen/src/generators/custom.ts","lineNumber":88,"sourceCode":"    await runCustomGenerator({\n      project,\n      generator: selectedGenerator,\n      bypassArgs: opts.args,\n      configPath: opts.config\n    });\n  } catch (err) {\n    // pass any GeneratorErrors through to root\n    if (err instanceof GeneratorError) {\n      throw err;\n    }\n\n    // capture any other errors and throw as GeneratorErrors\n    let message = \"Failed to run generator\";\n    if (err instanceof Error) {\n      message = err.message;\n    }\n\n    throw new GeneratorError(message, {\n      type: \"plop_error_running_generator\"\n    });\n  } finally {\n    if (isOnboarding) {\n      logger.log();\n      logger.info(`Congrats! You just ran your first Turborepo generator`);\n      logger.dimmed(\n        \"Learn more about custom Turborepo generators - https://turborepo.dev/docs/guides/generating-code#custom-generators\"\n      );\n    }\n  }\n\n  logger.log();\n  logger.bold(logger.turboGradient(\">>> Success!\"));\n}\n","sourceCodeStart":70,"sourceCodeEnd":104,"githubUrl":"https://github.com/vercel/turborepo/blob/f9245100cf0d31d96628804ead485f6bf226e55a/packages/turbo-gen/src/generators/custom.ts#L70-L104","documentation":"The turbo-gen custom generator wraps plop to run your plopfile. It lets GeneratorError instances pass through untouched. It wraps every other error from prompts or actions in a GeneratorError with code plop_error_running_generator and the original message. The error means the plopfile threw, not that a configured action merely reported failure.","triggerScenarios":"The plopfile throws during runPrompts or runActions: an invalid action type, a missing helper or partial registered at load time, a template compile error, or any runtime throw in your own action code. The catch converts the thrown value to a GeneratorError, keeping the message when err instanceof Error.","commonSituations":"A plopfile references a handlebars helper that is not registered. An action uses type \"add\" with a template path outside basePath. A custom action function throws. TypeScript or import errors inside the plopfile surface here.","solutions":["Read the message inside the GeneratorError; it carries the original error text","Open the plopfile named in the generator output and fix the throwing line","Verify every setHelper, setPartial, and setGenerator call matches what actions reference","Run the plopfile standalone with npx plop in the same directory to reproduce the failure faster"],"exampleFix":"// before: plopfile uses an unregistered helper\nmodule.exports = function (plop) {\n  plop.setGenerator(\"widget\", {\n    prompts: [],\n    actions: [{ type: \"add\", path: \"src/{{ PascalName }}.ts\", templateFile: \"tpl.hbs\" }]\n  });\n};\n// after: register the helper used by the template\nmodule.exports = function (plop) {\n  plop.setHelper(\"PascalName\", (s) => s.charAt(0).toUpperCase() + s.slice(1));\n  plop.setGenerator(\"widget\", {\n    prompts: [],\n    actions: [{ type: \"add\", path: \"src/{{ PascalName name }}.ts\", templateFile: \"tpl.hbs\" }]\n  });\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"import { GeneratorError } from \"turbo-gen\"; // or your local GeneratorError type\n\nfunction isGeneratorError(err: unknown): err is GeneratorError {\n  return err instanceof Error && \"type\" in err && typeof (err as GeneratorError).type === \"string\";\n}","tryCatchPattern":"try {\n  await runGenerator();\n} catch (err) {\n  if (err instanceof GeneratorError && err.type === \"plop_error_running_generator\") {\n    // err.message carries the underlying plopfile error; log and stop\n    console.error(`generator failed: ${err.message}`);\n    process.exitCode = 1;\n  } else {\n    throw err;\n  }\n}","preventionTips":["Test plopfiles with npx plop before wiring them into turbo gen","Register every helper and partial the templates reference","Keep action types and template paths within the plopfile's base directory"],"tags":["turbo-gen","plop","custom-generator","scaffolding","runtime-error"],"backgroundTag":"generator-runtime-error","analyzedSha":"f9245100cf0d31d96628804ead485f6bf226e55a","analyzedAt":"2026-08-17T10:46:15.696Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}