{"record":{"id":"c4edbebfd043db34","repo":"BabylonJS/Babylon.js","slug":"invalid-value-for-templated-input-name-val","errorCode":null,"errorMessage":"Invalid value for templated input \"${name}\": ${value}.","messagePattern":"Invalid value for templated input \"(.+?)\": (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FlowGraph/flowGraphPathConverterComponent.ts","lineNumber":147,"sourceCode":"            return ExtractRefSubstitution(template, name, pointer);\r\n        }\r\n    }\r\n    throw new Error(`Invalid value for templated input \"${name}\": got ${typeof raw}.`);\r\n}\r\n\r\nfunction GetPlaceholderIndex(template: string, name: string): number {\r\n    const placeholders = [`{${name}}`, `[${name}]`];\r\n    return template.split(\"/\").findIndex((segment) => placeholders.indexOf(segment) >= 0);\r\n}\r\n\r\nfunction GetPlaceholderParentSegment(template: string, name: string): string | undefined {\r\n    const placeholderIndex = GetPlaceholderIndex(template, name);\r\n    return placeholderIndex > 0 ? template.split(\"/\")[placeholderIndex - 1] : undefined;\r\n}\r\n\r\nfunction AssertNonNegativeInt(value: number, name: string): void {\r\n    if (typeof value !== \"number\" || value < 0 || !Number.isFinite(value)) {\r\n        throw new Error(`Invalid value for templated input \"${name}\": ${value}.`);\r\n    }\r\n}\r\n\r\nfunction ExtractRefSubstitution(template: string, name: string, refValue: string): string {\r\n    const templateSegments = template.split(\"/\");\r\n    const placeholders = [`{${name}}`, `[${name}]`];\r\n    const placeholderIndex = templateSegments.findIndex((s) => placeholders.indexOf(s) >= 0);\r\n    const refSegments = refValue.split(\"/\");\r\n    if (placeholderIndex >= 0 && placeholderIndex < refSegments.length && refSegments[placeholderIndex] !== \"\") {\r\n        return refSegments[placeholderIndex];\r\n    }\r\n    for (let i = refSegments.length - 1; i >= 0; i--) {\r\n        if (refSegments[i] !== \"\") {\r\n            return refSegments[i];\r\n        }\r\n    }\r\n    return refValue;\r\n}\r","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FlowGraph/flowGraphPathConverterComponent.ts#L129-L165","documentation":"FlowGraphPathConverterComponent validates templated path inputs at runtime. Values substituted into a template like \"{i}/position\" must be non-negative finite numbers; AssertNonNegativeInt throws this error when a value is not a number, is negative, or is NaN/Infinity.","triggerScenarios":"Calling ResolveTemplateSubstitution (e.g. via a path-converter component consuming a templated input) with a value that is negative, non-numeric, NaN, or Infinity, such as an index of -1 from an unfulfilled lookup.","commonSituations":"An array indexOf() returning -1, an unset animation frame/index input defaulting to -1, or a JSON-parsed value arriving as a string instead of a number.","solutions":["Check the value passed to the templated input is a finite number >= 0 before the component resolves the template","Fix upstream logic that produces -1 (e.g. indexOf miss) by guarding the lookup","Coerce/parse string inputs with Number() and validate before assignment"],"exampleFix":"// before\ncomponent.input.value = arr.indexOf(item); // -1 when missing\n// after\nconst idx = arr.indexOf(item);\ncomponent.input.value = idx >= 0 ? idx : 0;","handlingStrategy":"validation","validationCode":"function isValidIndex(v) { return typeof v === 'number' && Number.isFinite(v) && v >= 0; }\nif (!isValidIndex(value)) throw new RangeError(`expected non-negative finite int, got ${value}`);","typeGuard":"function isNonNegativeInt(v: unknown): v is number { return typeof v === 'number' && Number.isFinite(v) && v >= 0; }","tryCatchPattern":"try { graph.resolveTemplates(); } catch (e) { if (e.message.includes('Invalid value for templated input')) { console.error('Bad template substitution value:', e.message); } else { throw e; } }","preventionTips":["Validate all indices/numeric template inputs with a non-negative finite-number check","Guard indexOf-style lookups against -1 before assigning","Log the template name and value on failure for quick diagnosis"],"tags":["flow-graph","validation","bad-input"],"backgroundTag":"invalid-parameter-value","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}