MCPcopy Index your code
hub / github.com/bernaferrari/FigmaToCode / safeRun

Function safeRun

apps/plugin/plugin-src/code.ts:88–132  ·  view source on GitHub ↗
(settings: PluginSettings)

Source from the content-addressed store, hash-verified

86// Used to prevent running from happening again.
87let isLoading = false;
88const safeRun = async (settings: PluginSettings) => {
89 console.log(
90 "[DEBUG] safeRun - Called with isLoading =",
91 isLoading,
92 "selectionCount =",
93 figma.currentPage.selection.length,
94 );
95 if (isLoading === false) {
96 try {
97 isLoading = true;
98 console.log("[DEBUG] safeRun - Starting run execution");
99 await run(settings);
100 console.log("[DEBUG] safeRun - Run execution completed");
101 // hack to make it not immediately set to false when complete. (executes on next frame)
102 setTimeout(() => {
103 console.log("[DEBUG] safeRun - Resetting isLoading to false");
104 isLoading = false;
105 }, 1);
106 } catch (e) {
107 console.log("[DEBUG] safeRun - Error caught in execution");
108 isLoading = false; // Make sure to reset the flag on error
109 if (e && typeof e === "object" && "message" in e) {
110 const error = e as Error;
111 console.log("error: ", error.stack);
112 figma.ui.postMessage({ type: "error", error: error.message });
113 } else {
114 // Handle non-standard errors or unknown error types
115 const errorMessage = String(e);
116 console.log("Unknown error: ", errorMessage);
117 figma.ui.postMessage({
118 type: "error",
119 error: errorMessage || "Unknown error occurred",
120 });
121 }
122
123 // Send a message to reset the UI state
124 figma.ui.postMessage({ type: "conversion-complete", success: false });
125 }
126 } else {
127 console.log(
128 "[DEBUG] safeRun - Skipping execution because isLoading =",
129 isLoading,
130 );
131 }
132};
133
134const standardMode = async () => {
135 console.log("[DEBUG] standardMode - Starting standard mode initialization");

Callers 2

initSettingsFunction · 0.85
standardModeFunction · 0.85

Calls 1

runFunction · 0.90

Tested by

no test coverage detected