slint-ui/slint · warning

Could not fetch variable

Error message

Could not fetch variable ${variableId}:

What it means

In the Figma inspector backend, getOriginalVariableData fetches a Figma variable by id via the Figma plugin API. If the API call throws, the helper logs this warning and returns null so callers must handle a missing variable gracefully. It indicates the variable could not be resolved (deleted, inaccessible, or a plugin-API failure).

Solutions

  1. Check the returned null in the caller and skip or substitute a default for the unresolved variable
  2. Verify the variableId against the current Figma file (re-export or re-fetch the variable list)
  3. Confirm the plugin has access to the referenced variable collections/libraries
  4. Add retry or fallback rendering (e.g. use the alias name only) when the variable cannot be fetched

Example fix

// before
const data = await getOriginalVariableData(id);
const value = data.value;
// after
const data = await getOriginalVariableData(id);
if (!data) {
  console.log(`Variable ${id} unavailable, using fallback`);
  return fallbackValue;
}
const value = data.value;
Defensive patterns

Strategy: fallback

Validate before calling

if (!variableId || typeof variableId !== 'string') return null; // skip fetch early

Type guard

function isFigmaVariable(v) {
  return v != null && typeof v === 'object' && typeof v.id === 'string' && 'name' in v;
}

Try / catch

let variable = null;
try {
  variable = await figma.variables.getVariableByIdAsync(id);
} catch (e) {
  console.warn(`Could not fetch variable ${id}:`, e);
  variable = null;
}
if (!variable) return placeholderFor(id);

Prevention

When it happens

Trigger: Calling originalVariable()/getOriginalVariableData with a variableId that no longer exists in the Figma file, belongs to a team/file the plugin cannot access, or when the Figma plugin API is unavailable.

Common situations: Designs referencing variables that were deleted or moved to another library; stale cached ids in exported data; plugin run in a context without access to the referenced variable collections.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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

Appendix: source

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

}

// Extract hierarchy from variable name (e.g. "colors/primary/base" → ["colors", "primary", "base"])
export function extractHierarchy(name: string): string[] {
    // First try splitting by slashes (the expected format)
    if (name.includes("/")) {
        return name.split("/").map((part) => sanitizePropertyName(part));
    }

    // Default case for simple names
    return [sanitizePropertyName(name)];
}

// Helper function to get original Figma variable data
async function getOriginalVariableData(variableId: string) {
    try {
        return await figma.variables.getVariableByIdAsync(variableId);
    } catch (error) {
        console.warn(`Could not fetch variable ${variableId}:`, error);
        return null;
    }
}

// Helper function to follow a reference chain to find a concrete value
async function followChainToConcreteValue(
    refId: string,
    modeName: string,
    visited: Set<string> = new Set(),
): Promise<string | null> {
    if (visited.has(refId)) {
        return null; // Circular reference in the chain
    }
    visited.add(refId);

    // Get the original Figma variable data
    const originalVariable = await getOriginalVariableData(refId);
    if (!originalVariable) {

View on GitHub (pinned to bb937076de)