{"record":{"id":"dbe403e5352a629b","repo":"slint-ui/slint","slug":"could-not-fetch-variable-variableid","errorCode":null,"errorMessage":"Could not fetch variable ${variableId}:","messagePattern":"Could not fetch variable (.+?):","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"tools/figma-inspector/backend/utils/export-variables.ts","lineNumber":128,"sourceCode":"}\n\n// Extract hierarchy from variable name (e.g. \"colors/primary/base\" → [\"colors\", \"primary\", \"base\"])\nexport function extractHierarchy(name: string): string[] {\n    // First try splitting by slashes (the expected format)\n    if (name.includes(\"/\")) {\n        return name.split(\"/\").map((part) => sanitizePropertyName(part));\n    }\n\n    // Default case for simple names\n    return [sanitizePropertyName(name)];\n}\n\n// Helper function to get original Figma variable data\nasync function getOriginalVariableData(variableId: string) {\n    try {\n        return await figma.variables.getVariableByIdAsync(variableId);\n    } catch (error) {\n        console.warn(`Could not fetch variable ${variableId}:`, error);\n        return null;\n    }\n}\n\n// Helper function to follow a reference chain to find a concrete value\nasync function followChainToConcreteValue(\n    refId: string,\n    modeName: string,\n    visited: Set<string> = new Set(),\n): Promise<string | null> {\n    if (visited.has(refId)) {\n        return null; // Circular reference in the chain\n    }\n    visited.add(refId);\n\n    // Get the original Figma variable data\n    const originalVariable = await getOriginalVariableData(refId);\n    if (!originalVariable) {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/tools/figma-inspector/backend/utils/export-variables.ts#L110-L146","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the returned null in the caller and skip or substitute a default for the unresolved variable","Verify the variableId against the current Figma file (re-export or re-fetch the variable list)","Confirm the plugin has access to the referenced variable collections/libraries","Add retry or fallback rendering (e.g. use the alias name only) when the variable cannot be fetched"],"exampleFix":"// before\nconst data = await getOriginalVariableData(id);\nconst value = data.value;\n// after\nconst data = await getOriginalVariableData(id);\nif (!data) {\n  console.log(`Variable ${id} unavailable, using fallback`);\n  return fallbackValue;\n}\nconst value = data.value;","handlingStrategy":"fallback","validationCode":"if (!variableId || typeof variableId !== 'string') return null; // skip fetch early","typeGuard":"function isFigmaVariable(v) {\n  return v != null && typeof v === 'object' && typeof v.id === 'string' && 'name' in v;\n}","tryCatchPattern":"let variable = null;\ntry {\n  variable = await figma.variables.getVariableByIdAsync(id);\n} catch (e) {\n  console.warn(`Could not fetch variable ${id}:`, e);\n  variable = null;\n}\nif (!variable) return placeholderFor(id);","preventionTips":["Re-validate referenced variable ids when the Figma file or library changes","Treat every getVariableByIdAsync result as nullable and code for the null path","Sync variable libraries regularly so referenced ids stay valid"],"tags":["figma","api","network","null-handling"],"backgroundTag":"api-request-failed","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}