{"record":{"id":"b10fccb2fb5ebe60","repo":"yikart/AiToEarn","slug":"responsecode-configeditorvalidationfailed","errorCode":"ResponseCode.ConfigEditorValidationFailed","errorMessage":"ConfigEditorValidationFailed","messagePattern":"ConfigEditorValidationFailed","errorType":"error_code","errorClass":"AppException","httpStatus":null,"severity":"error","filePath":"project/aitoearn-backend/libs/config-editor/src/config-editor.service.ts","lineNumber":66,"sourceCode":"\n  private parseConfig(content: string, format: ConfigFileFormat) {\n    try {\n      return format === ConfigFileFormat.Json\n        ? JSON.parse(content)\n        : parseYaml(content)\n    }\n    catch (error) {\n      throw new AppException(\n        ResponseCode.ConfigEditorParseFailed,\n        error instanceof Error ? error.message : String(error),\n      )\n    }\n  }\n\n  private validateConfigValue(config: unknown): Record<string, unknown> {\n    const schema = isZodDto(this.config.schema) ? this.config.schema.schema : this.config.schema\n    if (!(schema instanceof z.ZodType)) {\n      throw new AppException(ResponseCode.ConfigEditorValidationFailed)\n    }\n\n    const result = schema.safeParse(config)\n    if (!result.success) {\n      throw new AppException(ResponseCode.ConfigEditorValidationFailed, z.prettifyError(result.error))\n    }\n    return result.data as Record<string, unknown>\n  }\n\n  private serializeConfig(config: Record<string, unknown>, format: ConfigFileFormat) {\n    if (format === ConfigFileFormat.Json) {\n      return `${JSON.stringify(config, null, 2)}\\n`\n    }\n    return stringifyYaml(config)\n  }\n\n  private async readConfigFile(configPath: string) {\n    try {","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/libs/config-editor/src/config-editor.service.ts#L48-L84","documentation":"validateConfigValue requires the ConfigEditorConfig.schema to be a usable Zod schema — either a Zod DTO (from createZodDto, unwrapped via isZodDto) or a raw z.ZodType instance. If after that unwrapping the value is not a z.ZodType, the library cannot validate anything and throws ConfigEditorValidationFailed with no message.","triggerScenarios":"ConfigEditorModule is registered with a schema that is neither a Zod DTO nor a z.ZodType: e.g. a plain object, a class without createZodDto, a JSON-Schema/class-validator schema, undefined/null schema, or a zod version mismatch making `instanceof z.ZodType` fail across duplicate zod copies.","commonSituations":"Passing a plain TS interface (types vanish at runtime); passing a class decorated for class-validator instead of a Zod DTO; importing z from two different zod package instances (v3 vs v4 or duplicate installs) so instanceof fails; forgetting the schema option entirely.","solutions":["Pass a zod schema (z.object({...})) or a createZodDto(...) result as the schema option","Check `pnpm why zod` / lockfile for duplicate zod versions; dedupe so the same zod instance is shared with @yikart/common","If using a ZodDto class, make sure it was created with createZodDto so isZodDto recognizes it","Log/inspect the schema value at registration to confirm it is defined and non-null"],"exampleFix":"// before\nConfigEditorModule.register({ configPath: 'config/app.yaml', schema: AppConfig }) // plain interface\n// after\nconst AppConfigSchema = z.object({ port: z.number() })\nConfigEditorModule.register({ configPath: 'config/app.yaml', schema: AppConfigSchema })","handlingStrategy":"validation","validationCode":"import { z } from 'zod'\nif (!(schema instanceof z.ZodType) && !isZodDto(schema))\n  throw new Error('ConfigEditor schema must be a zod schema or createZodDto result')","typeGuard":"function isUsableSchema(s: unknown): s is z.ZodType {\n  const inner = isZodDto(s) ? s.schema : s\n  return inner instanceof z.ZodType\n}","tryCatchPattern":"try {\n  editor.validateConfig(payload)\n} catch (e) {\n  if (e instanceof AppException && e.code === ResponseCode.ConfigEditorValidationFailed && !e.message)\n    logger.error('Schema itself is not a ZodType — fix module registration')\n  throw e\n}","preventionTips":["Only pass zod schemas or createZodDto classes as schema","Dedupe zod versions (`pnpm why zod`) so instanceof checks hold","Never pass plain TS interfaces or class-validator classes as schema","Add a unit test asserting the module registers with a valid schema"],"tags":["config","validation","zod","schema"],"backgroundTag":"invalid-validation-schema","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}