BabylonJS/Babylon.js · error · Error

Invalid value for templated input "${name}": ${value}.

Error message

Invalid value for templated input "${name}": ${value}.

What it means

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.

Source

Thrown at packages/dev/core/src/FlowGraph/flowGraphPathConverterComponent.ts:147

            return ExtractRefSubstitution(template, name, pointer);
        }
    }
    throw new Error(`Invalid value for templated input "${name}": got ${typeof raw}.`);
}

function GetPlaceholderIndex(template: string, name: string): number {
    const placeholders = [`{${name}}`, `[${name}]`];
    return template.split("/").findIndex((segment) => placeholders.indexOf(segment) >= 0);
}

function GetPlaceholderParentSegment(template: string, name: string): string | undefined {
    const placeholderIndex = GetPlaceholderIndex(template, name);
    return placeholderIndex > 0 ? template.split("/")[placeholderIndex - 1] : undefined;
}

function AssertNonNegativeInt(value: number, name: string): void {
    if (typeof value !== "number" || value < 0 || !Number.isFinite(value)) {
        throw new Error(`Invalid value for templated input "${name}": ${value}.`);
    }
}

function ExtractRefSubstitution(template: string, name: string, refValue: string): string {
    const templateSegments = template.split("/");
    const placeholders = [`{${name}}`, `[${name}]`];
    const placeholderIndex = templateSegments.findIndex((s) => placeholders.indexOf(s) >= 0);
    const refSegments = refValue.split("/");
    if (placeholderIndex >= 0 && placeholderIndex < refSegments.length && refSegments[placeholderIndex] !== "") {
        return refSegments[placeholderIndex];
    }
    for (let i = refSegments.length - 1; i >= 0; i--) {
        if (refSegments[i] !== "") {
            return refSegments[i];
        }
    }
    return refValue;
}

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Check the value passed to the templated input is a finite number >= 0 before the component resolves the template
  2. Fix upstream logic that produces -1 (e.g. indexOf miss) by guarding the lookup
  3. Coerce/parse string inputs with Number() and validate before assignment

Example fix

// before
component.input.value = arr.indexOf(item); // -1 when missing
// after
const idx = arr.indexOf(item);
component.input.value = idx >= 0 ? idx : 0;
Defensive patterns

Strategy: validation

Validate before calling

function isValidIndex(v) { return typeof v === 'number' && Number.isFinite(v) && v >= 0; }
if (!isValidIndex(value)) throw new RangeError(`expected non-negative finite int, got ${value}`);

Type guard

function isNonNegativeInt(v: unknown): v is number { return typeof v === 'number' && Number.isFinite(v) && v >= 0; }

Try / catch

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; } }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must be positive", "Invalid value": how libraries reject invalid parameter values (ValueError, ArgumentError, INVALID_PARAMETER_VALUE) — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/c4edbebfd043db34. Report an issue: GitHub.