{"record":{"id":"b5a893a170a42fbf","repo":"PaddlePaddle/PaddleOCR","slug":"ocr-pipeline-config-must-be-an-object-or-yaml-text","errorCode":null,"errorMessage":"OCR pipeline config must be an object or YAML text.","messagePattern":"OCR pipeline config must be an object or YAML text\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"paddleocr-js/packages/core/src/pipelines/ocr/config.ts","lineNumber":88,"sourceCode":"    text_det_limit_type: runtimeDefaults.text_det_limit_type ?? \"max\",\n    text_det_max_side_limit: runtimeDefaults.text_det_max_side_limit ?? 4000,\n    text_det_thresh: runtimeDefaults.text_det_thresh ?? 0.3,\n    text_det_box_thresh: runtimeDefaults.text_det_box_thresh ?? 0.6,\n    text_det_unclip_ratio: runtimeDefaults.text_det_unclip_ratio ?? 2.0,\n    text_rec_score_thresh: runtimeDefaults.text_rec_score_thresh ?? 0\n  };\n}\n\nfunction parsePipelineConfigInput(input: unknown): YamlObject {\n  if (typeof input === \"string\") {\n    const parsed = yaml.load(input);\n    if (!isPlainObject(parsed)) {\n      throw new Error(\"OCR pipeline config text must decode to an object.\");\n    }\n    return parsed;\n  }\n  if (!isPlainObject(input)) {\n    throw new Error(\"OCR pipeline config must be an object or YAML text.\");\n  }\n  return input;\n}\n\nfunction addFeatureWarning(warnings: string[], featureName: string, reason?: string): void {\n  warnings.push(\n    `${featureName} is not yet supported in PaddleOCR.js${reason ? `: ${reason}` : \"\"}.`\n  );\n}\n\nfunction getModuleModelName(moduleConfig: YamlObject | null): string | null {\n  return typeof moduleConfig?.model_name === \"string\" ? moduleConfig.model_name : null;\n}\n\nfunction validateModuleAsset(modulePath: string, modelName: string | null): void {\n  if (!modelName) {\n    throw new Error(\n      `${modulePath}.model_name must be provided when ${modulePath}.model_dir is set.`","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr-js/packages/core/src/pipelines/ocr/config.ts#L70-L106","documentation":"Thrown by parsePipelineConfigInput() when the non-string input is not a plain object — e.g. null, an array, a number, or a class instance. The API accepts exactly two shapes: a YAML string or a plain JS object; anything else is rejected before any field is read.","triggerScenarios":"Calling normalizeOcrPipelineConfig(null), with an array of config objects, with a JSON.parse result that is an array, or with undefined after a failed lookup (config from a map key that does not exist).","commonSituations":"Defaulting a missing config to null/undefined and passing it through; passing a Map or class-wrapped config; spreading an array of partial configs instead of merging into an object.","solutions":["Pass a plain object literal or a YAML string","Guard the call site: skip or supply a default object when the config variable is null/undefined","If building config programmatically, verify Object.prototype.toString or typeof before calling"],"exampleFix":"// before\nconst config = configs[name]; // undefined when name missing\nnormalizeOcrPipelineConfig(config); // throws\n\n// after\nconst config = configs[name] ?? { pipeline_name: \"OCR\" };\nnormalizeOcrPipelineConfig(config);","handlingStrategy":"type-guard","validationCode":"if (typeof input !== \"string\" && (typeof input !== \"object\" || input === null || Array.isArray(input))) {\n  throw new TypeError(\"Pipeline config must be a YAML string or plain object\");\n}","typeGuard":"function isPipelineConfigInput(input: unknown): input is string | Record<string, unknown> {\n  return typeof input === \"string\" || (typeof input === \"object\" && input !== null && !Array.isArray(input));\n}","tryCatchPattern":null,"preventionTips":["Default missing configs to a valid object, never null/undefined","Type the parameter as string | object at the call boundary","Beware JSON.parse results that are arrays — they pass 'object' typeof but fail here"],"tags":["paddleocr","config","typescript","validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}