{"record":{"id":"889f91250726b4a0","repo":"Egonex-AI/Understand-Anything","slug":"figma-token-is-not-set-create-a-personal-access-t","errorCode":null,"errorMessage":"FIGMA_TOKEN is not set. Create a personal access token at https://www.figma.com/settings, then run: export FIGMA_TOKEN=<token>","messagePattern":"FIGMA_TOKEN is not set\\. Create a personal access token at https://www\\.figma\\.com/settings, then run: export FIGMA_TOKEN=<token>","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"understand-anything-plugin/packages/core/src/figma/source/api-source.ts","lineNumber":17,"sourceCode":"import type { FigmaSource, FigmaDocument, FigmaStyles } from \"./types.js\";\n\nconst FIGMA_API = \"https://api.figma.com/v1\";\n\nexport function parseFileKey(urlOrKey: string): string {\n  const m = urlOrKey.match(/figma\\.com\\/(?:file|design)\\/([A-Za-z0-9]+)/);\n  if (m) return m[1];\n  if (/^[A-Za-z0-9]+$/.test(urlOrKey.trim())) return urlOrKey.trim();\n  throw new Error(`Could not parse a Figma file key from: ${urlOrKey}`);\n}\n\nexport class FigmaApiSource implements FigmaSource {\n  private readonly token: string;\n\n  constructor(private readonly fileKey: string, token: string | undefined = process.env.FIGMA_TOKEN) {\n    if (!token) {\n      throw new Error(\n        \"FIGMA_TOKEN is not set. Create a personal access token at \" +\n        \"https://www.figma.com/settings, then run: export FIGMA_TOKEN=<token>\",\n      );\n    }\n    this.token = token;\n  }\n\n  private async get<T>(path: string): Promise<T> {\n    // Token travels only in the header — never in the URL, never logged.\n    const res = await fetch(`${FIGMA_API}${path}`, { headers: { \"X-Figma-Token\": this.token } });\n    if (!res.ok) {\n      throw new Error(`Figma API ${path} failed: ${res.status} ${res.statusText}`);\n    }\n    return (await res.json()) as T;\n  }\n\n  fetchDocument(): Promise<FigmaDocument> {\n    return this.get<FigmaDocument>(`/files/${this.fileKey}`);","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/Egonex-AI/Understand-Anything/blob/32944829e7a63a9fa9c55d811d7f98a9530c6a6a/understand-anything-plugin/packages/core/src/figma/source/api-source.ts#L1-L35","documentation":"Thrown by the FigmaApiSource constructor when the resolved token is falsy. The token defaults to process.env.FIGMA_TOKEN and can be overridden via the constructor's second argument; if neither is a non-empty string the API client cannot authenticate and refuses to construct. The message intentionally points the user at the Figma settings page and the export command.","triggerScenarios":"Constructing new FigmaApiSource(fileKey) (or with token omitted) when FIGMA_TOKEN is unset, empty, or whitespace — note the guard checks truthiness, not non-empty-after-trim, so a whitespace-only value still passes. Also fires when an explicit token argument is undefined/null/empty string.","commonSituations":"Running in a fresh shell without exporting FIGMA_TOKEN; the token set in one shell but not in a CI runner or a child process spawned with a sanitised env; a .env file that is not loaded; deploying to an environment where the secret was forgotten.","solutions":["Create a personal access token at https://www.figma.com/settings and run export FIGMA_TOKEN=<token> in the same shell before launching.","Pass the token explicitly: new FigmaApiSource(fileKey, myToken).","Ensure the token is exported in the environment of any CI runner, container, or spawned child process (inherit env or inject the secret).","Add a startup assertion that process.env.FIGMA_TOKEN is a non-empty string so the failure surfaces before work begins."],"exampleFix":"// before\nconst src = new FigmaApiSource(fileKey);\n// after\nconst src = new FigmaApiSource(fileKey, process.env.FIGMA_TOKEN);\n// and ensure the env is populated: export FIGMA_TOKEN=figd_...","handlingStrategy":"validation","validationCode":"const token = process.env.FIGMA_TOKEN;\nif (!token || token.trim().length === 0) {\n  throw new Error('Set FIGMA_TOKEN before constructing FigmaApiSource');\n}\nconst src = new FigmaApiSource(fileKey, token);","typeGuard":"function hasFigmaToken(env: NodeJS.ProcessEnv): env is { FIGMA_TOKEN: string } {\n  return typeof env.FIGMA_TOKEN === 'string' && env.FIGMA_TOKEN.length > 0;\n}","tryCatchPattern":"try { const src = new FigmaApiSource(fileKey, token); } catch (e) { if (/FIGMA_TOKEN/.test(String((e as Error).message))) { /* surface env setup guidance */ } throw e; }","preventionTips":["Add a startup assertion that process.env.FIGMA_TOKEN is a non-empty string.","Load secrets from a .env file or secret manager before constructing the client.","In CI, inject FIGMA_TOKEN as a masked environment variable."],"tags":["figma","authentication","configuration","environment"],"backgroundTag":null,"analyzedSha":"32944829e7a63a9fa9c55d811d7f98a9530c6a6a","analyzedAt":"2026-08-12T10:25:44.261Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}