- getmetadata vs getscreenshot - Error Recovery After Failed usefigma - Cleanup Pattern - Recommended Workflow
Part of the use_figma skill. How to debug, validate, and recover from errors.
get_metadata vs get_screenshotuse_figmaget_metadata vs get_screenshotAfter each use_figma call, validate results using the right tool for the job. Do NOT reach for get_screenshot every time — it is expensive and should be reserved for visual checks.
get_metadata — Use for intermediate validation (preferred)get_metadata returns an XML tree of node IDs, types, names, positions, and sizes. Use it to confirm:
property=value conventionExample: After creating a ComponentSet with 120 variants, call get_metadata on the
ComponentSet node to verify all 120 children exist with correct names, sizes, and positions
— without waiting for a full render.
When to use get_metadata:
get_screenshot — Use after each major creation milestoneget_screenshot renders a pixel-accurate image. It is the only way to verify visual correctness (colors, typography rendering, effects, variable mode resolution). It is slower and produces large responses, so don't call it after every single use_figma — but do call it after each major milestone to catch visual problems early.
When to use get_screenshot:
What to look for in screenshots — these are the most commonly missed issues:
use_figmaTHIS IS NOT OPTIONAL. Every
use_figmaerror MUST trigger the recovery steps below. Skipping these steps leaves orphaned nodes in the file that will cause duplicates and inconsistencies on retry.
Scripts can partially execute before hitting an error. A failed use_figma does NOT roll back — nodes created before the error line persist in the file. This leaves the file in an inconsistent, partially-modified state.
Mandatory recovery steps when use_figma returns an error (DO NOT SKIP):
get_metadata on the parent node (section, page, or ComponentSet) to see what was partially created.get_metadata doesn't make the damage clear (e.g. positions look fine but visual state is uncertain), call get_screenshot to assess visual damage.page.findChildren() to locate stray nodes.Example: A script creating 8 components fails on component #5.
Components 1-4 exist on the page. A naive retry creates components 1-8 again,
leaving 12 components total (4 orphaned duplicates). Always clean up first.
// Cleanup pattern: find and remove orphaned nodes from a failed run
(async () => {
try {
const page = figma.currentPage;
// Find orphaned components that weren't combined into a ComponentSet
const orphans = page.findChildren(n =>
n.type === 'COMPONENT' && n.name.includes('variant=')
);
for (const orphan of orphans) orphan.remove();
figma.closePlugin('Cleaned up ' + orphans.length + ' orphaned nodes');
} catch(e) { figma.closePluginWithFailure(e.toString()); }
})()
1. use_figma → Create/modify nodes
2. get_metadata → Verify structure, counts, names, positions (fast, cheap)
3. use_figma → Fix any structural issues found
4. get_metadata → Re-verify fixes
5. ... repeat as needed ...
6. get_screenshot → Visual check after each major milestone
⚠️ ON ERROR at any step:
a. get_metadata → Inspect partial state (always do this first)
b. get_screenshot → Only if metadata doesn't make the damage clear
c. use_figma → Clean up orphaned/incomplete nodes
d. THEN retry the failed operation