{"record":{"id":"1bd5723476c740f6","repo":"mastra-ai/mastra","slug":"factory-rule-version-is-required","errorCode":null,"errorMessage":"Factory rule version is required.","messagePattern":"Factory rule version is required\\.","errorType":"validation","errorClass":"FactoryRuleValidationError","httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/rules/defaults.ts","lineNumber":653,"sourceCode":"  return result;\n}\n\nexport function mergeFactoryRuleOverrides(\n  base: FactoryRulesOverrides,\n  overrides: FactoryRulesOverrides = {},\n): Omit<FactoryRules, 'version'> {\n  return {\n    work: mergeBoardRules(base.work, overrides.work),\n    review: mergeBoardRules(base.review, overrides.review),\n    tools: mergeToolRules(base.tools, overrides.tools),\n    github: mergeGithubRules(base.github, overrides.github),\n    linear: mergeLinearRules(base.linear, overrides.linear),\n  };\n}\n\nexport function defaultFactoryRules(input: { version: string; overrides?: FactoryRulesOverrides }): FactoryRules {\n  if (typeof input?.version !== 'string' || input.version.trim().length === 0) {\n    throw new FactoryRuleValidationError('Factory rule version is required.');\n  }\n\n  const rules: FactoryRules = {\n    version: input.version.trim(),\n    ...mergeFactoryRuleOverrides(BUILT_IN_DEFAULTS, input.overrides),\n  };\n  assertFactoryRules(rules);\n  return rules;\n}\n\nexport function builtInFactoryRules(): FactoryRules {\n  return defaultFactoryRules({ version: DEFAULT_FACTORY_RULE_VERSION });\n}\n","sourceCodeStart":635,"sourceCodeEnd":667,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/rules/defaults.ts#L635-L667","documentation":"defaultFactoryRules requires an explicit, non-empty version string because the built-in rule defaults are versioned. If input.version is missing, not a string, or blank/whitespace, a FactoryRuleValidationError is thrown before any rules are merged. This guards against silently generating unversioned rule sets.","triggerScenarios":"Calling defaultFactoryRules({ version: ... }) with version undefined, null, a non-string, an empty string, or a whitespace-only string — e.g. defaultFactoryRules({}) or defaultFactoryRules({ version: config.rulesVersion }) where config.rulesVersion is unset.","commonSituations":"Environment variable for the rules version not set, config schema not validating the version field, upgrading the factory and forgetting the new required parameter, or passing the overrides object as the first argument by mistake.","solutions":["Pass a non-empty version string: defaultFactoryRules({ version: '2024-01' }) — it is trimmed before use.","Fill in the missing env/config value that supplies the version and validate it at startup.","If loading from user config, fall back to a pinned default version explicitly."],"exampleFix":"// before\ndefaultFactoryRules({ overrides: userOverrides });\n// after\ndefaultFactoryRules({ version: '2024-01', overrides: userOverrides });","handlingStrategy":"validation","validationCode":"function assertRulesVersion(v: unknown): string {\n  if (typeof v !== 'string' || v.trim().length === 0) throw new Error('version required');\n  return v.trim();\n}\ndefaultFactoryRules({ version: assertRulesVersion(config.rulesVersion), overrides });","typeGuard":"function hasVersion(input: unknown): input is { version: string; overrides?: FactoryRulesOverrides } {\n  return typeof input === 'object' && input !== null &&\n    typeof (input as any).version === 'string' && (input as any).version.trim().length > 0;\n}","tryCatchPattern":"try {\n  rules = defaultFactoryRules({ version });\n} catch (e) {\n  if (e instanceof FactoryRuleValidationError) rules = defaultFactoryRules({ version: FALLBACK_VERSION });\n  else throw e;\n}","preventionTips":["Make rules version a required, validated config field at startup.","Provide an explicit fallback default version in code.","Never pass overrides as the first argument positionally."],"tags":["validation","factory-rules","missing-argument","config"],"backgroundTag":"missing-required-argument","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}