slint-ui/slint · warning

Mode mismatch for variable

Error message

Mode mismatch for variable ${variable.name}: using fallback value from mode ${foundModeId} (index ${valueIndex}) for expected mode ${modeName}

What it means

During Figma variable export, the value for the requested mode was not found, but the variable had values for other modes. The exporter falls back to a value from a different mode (clamping the index into availableValues) and warns which mode the fallback came from, so output colors/text may not match the requested mode.

Solutions

  1. Publish the variable in every mode of its collection in Figma
  2. Ensure the requested modeName/mode id actually exists on the variable's collection
  3. Re-run export after refreshing the Figma variables snapshot
  4. Treat the warning as a data audit: enumerate variables lacking the mode and fix them at source

Example fix

// before
[foundModeId, value] = availableValues[valueIndex]; // silent-ish fallback
// after
if (!availableValues.some(([id]) => id === expectedModeId)) {
  throw new Error(`Variable ${variable.name} has no value for mode ${modeName}`);
}
Defensive patterns

Strategy: validation

Validate before calling

const modeValue = availableValues.find(([id]) => id === expectedModeId);
if (!modeValue) throw new Error(`Variable ${variable.name} missing mode ${modeName}`);

Type guard

function hasModeValue(v: { valuesByMode: Record<string, unknown> }, modeId: string): boolean {
  return Object.prototype.hasOwnProperty.call(v.valuesByMode, modeId);
}

Try / catch

try {
  formatVariableValue(variable, modeName);
} catch (e) {
  exportInfo.errors.add(e.message); // track mismatches instead of falling back silently
}

Prevention

When it happens

Trigger: exportFigmaVariablesToSeparateFiles resolves a variable per mode; the mode's value is absent (mode mismatch between the requested modeName and the variable's published modes), so a fallback index is computed.

Common situations: A variable was not published in every mode of its collection; new modes were added in Figma while some variables were not updated; export requests a mode id that the variable doesn't define.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16). Data as JSON: /api/errors/ed5db8a88b7b0628. Report an issue: GitHub.

Appendix: source

Thrown at tools/figma-inspector/backend/utils/export-variables.ts:1034

                                if (availableValues.length > 0) {
                                    // Try to map collection modes to different variable modes when possible
                                    // Get the index of this collection mode
                                    const collectionModeIndex =
                                        collection.modes.findIndex(
                                            (mode) =>
                                                mode.modeId ===
                                                collectionMode.modeId,
                                        );

                                    // Use different available values for different collection modes
                                    const valueIndex = Math.min(
                                        collectionModeIndex,
                                        availableValues.length - 1,
                                    );
                                    [foundModeId, value] =
                                        availableValues[valueIndex];

                                    console.warn(
                                        `Mode mismatch for variable ${variable.name}: using fallback value from mode ${foundModeId} (index ${valueIndex}) for expected mode ${modeName}`,
                                    );
                                }
                            }
                        }

                        // Skip if no value found at all
                        if (value === null) {
                            console.warn(
                                `No value found for variable ${variable.name} in mode ${modeName}`,
                            );
                            continue;
                        }

                        // Format value and resolve all references immediately
                        let formattedValue = "";
                        let comment: string | undefined;

View on GitHub (pinned to bb937076de)