{"record":{"id":"ff8ed4470d9631dd","repo":"hcengineering/platform","slug":"variable-matched-0-not-found","errorCode":null,"errorMessage":"Variable ${matched[0]} not found","messagePattern":"Variable (.+?) not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/importer/src/huly/parser.ts","lineNumber":69,"sourceCode":"      ;(data as any)[key] = this.resolveValue(value)\n    }\n    return data\n  }\n\n  private resolveValue (value: any): any {\n    if (typeof value === 'object') {\n      if (Array.isArray(value)) {\n        return value.map((v) => this.resolveValue(v))\n      } else {\n        return this.resolveProps(value)\n      }\n    } else if (typeof value === 'string') {\n      while (true) {\n        const matched = VARIABLE_REGEX.exec(value)\n        if (matched === null) break\n        const result = this.variables[matched[0]]\n        if (result === undefined) {\n          throw new Error(`Variable ${matched[0]} not found`)\n        } else {\n          value = value.replaceAll(matched[0], result)\n          VARIABLE_REGEX.lastIndex = 0\n        }\n      }\n      return value\n    }\n    return value\n  }\n}\n","sourceCodeStart":51,"sourceCodeEnd":80,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/packages/importer/src/huly/parser.ts#L51-L80","documentation":"The Huly YAML header parser supports variable interpolation: any ${VAR} token found in a string header value is replaced with a value from the parser's `variables` map. If the token is not present in that map, resolveValue throws 'Variable ${VAR} not found'. This keeps undefined placeholders from silently leaking into imported data.","triggerScenarios":"A YAML header in a parsed markdown file contains a ${...} placeholder (matching VARIABLE_REGEX) whose exact token (e.g. '${workspace}') is not a key in the variables passed to the parser; this runs during readYamlHeader -> resolveProps -> resolveValue, recursively for nested objects and arrays.","commonSituations":"Header references a variable the importer never defines; markdown content legitimately containing shell-style ${...} (e.g. code samples) placed in the YAML header; typo in variable name; variable defined with different casing or missing $ braces.","solutions":["Add the missing key to the parser's variables map (or pass it where the HulyFormatImporter constructs the parser) so the token resolves.","Correct or remove the ${...} placeholder in the file's YAML header if it is a typo or not needed.","If the ${...} text is literal content, move it out of the YAML header into the markdown body, or escape/rewrite it so VARIABLE_REGEX does not match."],"exampleFix":"// before (header uses undefined variable)\ntitle: Guide for ${product}\n// after (variable supplied to parser)\nnew HulyParser(variables: { '${product}': 'Huly' })","handlingStrategy":"try-catch","validationCode":"// pre-scan header strings for unresolved variables\nconst used = [...JSON.stringify(header).matchAll(/\\$\\{[^}]+\\}/g)].map((m) => m[0])\nconst missing = used.filter((v) => !(v in variables))\nif (missing.length > 0) throw new Error(`Unresolved variables: ${missing.join(', ')}`)","typeGuard":null,"tryCatchPattern":"try {\n  const header = parser.readYamlHeader(filePath)\n} catch (e) {\n  if ((e as Error).message.includes('not found') && /Variable \\$\\{/.test((e as Error).message)) {\n    const name = (e as Error).message.match(/Variable (\\$\\{[^}]+\\})/)?.[1]\n    console.error(`Define '${name}' in parser variables or remove it from ${filePath}`)\n  } else throw e\n}","preventionTips":["Keep the variables map co-located with the file set and cover all tokens used in headers.","Avoid putting code samples containing ${...} in the YAML header; keep them in the markdown body.","Lint headers for ${...} tokens and diff against the supplied variables before import.","Watch for regex lastIndex state on the shared VARIABLE_REGEX when reusing the parser."],"tags":["yaml","parser","interpolation","huly"],"backgroundTag":"undefined-variable","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}