diff --git a/packages/token-cli/src/createToken.ts b/packages/token-cli/src/createToken.ts index 8f6879a48..e0dbc40d3 100644 --- a/packages/token-cli/src/createToken.ts +++ b/packages/token-cli/src/createToken.ts @@ -62,18 +62,36 @@ export const createToken = ( if (!v) throw new Error(`can't find variable: ${it}`) - return { - [v.name]: { - value: resolveValue( - variableCollectionMap, - variableMap, - v.resolvedType, - v, - modeId - ), - }, + try { + const value = resolveValue( + variableCollectionMap, + variableMap, + v.resolvedType, + v, + modeId + ) + return { + [v.name]: { + value, + }, + } + } catch (e) { + if (e instanceof Error) { + // eslint-disable-next-line no-console + console.warn(`[warn]: ${e.message}`) + } + return undefined } }) + .filter( + ( + it + ): it is { + [x: string]: { + value: string + } + } => it !== undefined + ) .reduce((prev, current) => ({ ...prev, ...current, diff --git a/packages/token-cli/src/figma/index.ts b/packages/token-cli/src/figma/index.ts index 7506e67ac..504a3f8ce 100644 --- a/packages/token-cli/src/figma/index.ts +++ b/packages/token-cli/src/figma/index.ts @@ -106,13 +106,16 @@ export const resolveValue = ( // if alias, look at it recursively. if (typeof value === 'object' && 'type' in value && 'id' in value) { const v = variableMap.get(value.id) - if (!v) throw new Error(`can't find variable ${value.id}`) + if (!v) + throw new Error( + `can't find variable alias "${variable.name}:${value.id}"` + ) const variableCollection = variableCollectionMap.get(v.variableCollectionId) if (!variableCollection) throw new Error( - `can't find variable collection ${v.variableCollectionId}` + `can't find variable collection "${variable.name}:${v.variableCollectionId}"` ) return `{${variableCollection.name}.${v.name}}`