Skip to content

CanvasAnvil is an open source AI diagram maker and flowchart generator - an infinite-canvas diagram editor and self-hosted drawio alternative that writes editable .drawio files. Text to diagram, then fix nodes, layout and labels in place. Also AI presentations, interior design CAD/BOM, posters and infographics.

fix(cad): stop four catch blocks from hiding a failed patch apply

codingFeng1010cfbdc4ad974
diff --git a/client/shared/files/visual-assets.ts b/client/shared/files/visual-assets.ts
index 444d690..2821b69 100644
--- a/client/shared/files/visual-assets.ts
+++ b/client/shared/files/visual-assets.ts
@@ -95,6 +95,7 @@ const renderPdfPageCanvas = async (page: any, targetWidth = 980) => {
textBoxes.push({ text: str, x, y, w, h })
}
} catch {
+ // A page whose text layer will not decode still yields its image.
}
return { canvas, textBoxes, pageText: pageText.trim() }
@@ -850,6 +851,7 @@ export async function extractThirdPartyVisualAssets(
const errPayload = await resp.json()
detail = String(errPayload?.error || "")
} catch {
+ // The proxy did not send a JSON body; the status code below is enough.
}
throw new Error(
`Third-party parser proxy failed: ${resp.status}${detail ? ` - ${detail}` : ""}`,
diff --git a/client/shared/i18n/language.ts b/client/shared/i18n/language.ts
index 1e5e092..a97b09a 100644
--- a/client/shared/i18n/language.ts
+++ b/client/shared/i18n/language.ts
@@ -23,10 +23,12 @@ export function setUiLanguage(lang: UiLanguage) {
try {
document.documentElement.setAttribute("lang", lang === "zh" ? "zh-CN" : "en");
} catch {
+ // A blocked localStorage only means the old history lingers.
}
try {
window.dispatchEvent(new Event("ui-language-changed"));
} catch {
+ // No window to notify (server render, or a detached document).
}
}
diff --git a/client/workspaces/cad/CadWorkspace.tsx b/client/workspaces/cad/CadWorkspace.tsx
index 60f6c0e..37f488c 100644
--- a/client/workspaces/cad/CadWorkspace.tsx
+++ b/client/workspaces/cad/CadWorkspace.tsx
@@ -43,6 +43,7 @@ const tryParseJson = (text: string) => {
try {
return JSON.parse(text.slice(start, end + 1));
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
return null;
@@ -149,6 +150,7 @@ const extractLatestSvgFromText = (text: string) => {
latest = normalized;
}
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
@@ -358,6 +360,7 @@ export function CadWorkspace() {
}),
);
} catch {
+ // Losing one autosave is better than interrupting the user.
}
}, [cad2dSvg, cadPlan, cadAnalysisImages, cadBom, cadFocusPanel]);
@@ -515,6 +518,7 @@ export function CadWorkspace() {
try {
URL.revokeObjectURL(u);
} catch {
+ // The URL was already revoked, or never belonged to this document.
}
}
}
@@ -986,18 +990,22 @@ export function CadWorkspace() {
try {
localStorage.removeItem(CAD_WORKSPACE_STORAGE_KEY);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
try {
localStorage.removeItem(CAD_RENDERS_STORAGE_KEY);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
try {
localStorage.removeItem(CAD_ANALYSIS_IMAGES_STORAGE_KEY);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
try {
localStorage.removeItem(CAD_CHAT_STORAGE_KEY);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
void Promise.all([
cadStore.clear(CAD_RENDERS_KEY),
@@ -1008,6 +1016,7 @@ export function CadWorkspace() {
try {
localStorage.removeItem("CanvasAnvil-history-cad-v1");
} catch {
+ // A blocked localStorage only means the old history lingers.
}
setCadResetTick((x) => x + 1);
};
diff --git a/client/workspaces/cad/canvas/CadCanvas.tsx b/client/workspaces/cad/canvas/CadCanvas.tsx
index d3a917c..e5a9547 100644
--- a/client/workspaces/cad/canvas/CadCanvas.tsx
+++ b/client/workspaces/cad/canvas/CadCanvas.tsx
@@ -200,6 +200,7 @@ export function CadCanvas({
latestLoadedSvgRef.current = EMPTY_SENTINEL;
}
} catch {
+ // The editor iframe is gone or cross-origin; the retry ladder covers it.
}
};
diff --git a/client/workspaces/cad/chat/ChatPanel.tsx b/client/workspaces/cad/chat/ChatPanel.tsx
index 81217b6..28b7306 100644
--- a/client/workspaces/cad/chat/ChatPanel.tsx
+++ b/client/workspaces/cad/chat/ChatPanel.tsx
@@ -220,6 +220,7 @@ export function ChatPanel({
const parsed = JSON.parse(raw);
return formatCadPlanForDisplay(parsed);
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
const start = raw.indexOf("{");
const end = raw.lastIndexOf("}");
@@ -228,6 +229,7 @@ export function ChatPanel({
const parsed = JSON.parse(raw.slice(start, end + 1));
return formatCadPlanForDisplay(parsed);
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
return null;
@@ -261,6 +263,7 @@ export function ChatPanel({
return bomUpdatedText;
}
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
if (text.includes('"type"') && text.includes('"cad_images"')) {
return trText("(已提交装修图生成任务)", "(CAD drawing generation task submitted)");
@@ -300,6 +303,7 @@ export function ChatPanel({
}
if (parsedWhole?.type === "cad_bom") return bomUpdatedText;
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
return next;
};
@@ -327,6 +331,7 @@ export function ChatPanel({
try {
localStorage.removeItem(storageKey);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
setMessages([]);
setShowResetWarning(false);
@@ -366,6 +371,7 @@ export function ChatPanel({
const parsed = JSON.parse(jsonText);
if (parsed?.type === "cad_plan" && parsed?.plan) return parsed;
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
const fallback = extractJsonPayloadText(raw);
@@ -373,6 +379,7 @@ export function ChatPanel({
const parsed = JSON.parse(fallback);
if (parsed?.type === "cad_plan" && parsed?.plan) return parsed;
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
return null;
};
@@ -387,6 +394,7 @@ export function ChatPanel({
const parsed = JSON.parse(content);
if (typeof parsed?.prompt === "string" && parsed.prompt.trim()) return parsed.prompt.trim();
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
const line = content.replace(/\r?\n+/g, " ").trim();
return line || fallback;
@@ -466,6 +474,7 @@ export function ChatPanel({
const parsed = JSON.parse(text);
parsedType = String(parsed?.type || "").trim().toLowerCase();
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
const r = await runCodeAction(text, "cad");
@@ -564,6 +573,7 @@ export function ChatPanel({
return full;
}
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
const trimmed = raw.trim();
@@ -575,6 +585,7 @@ export function ChatPanel({
return full;
}
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
return "";
@@ -599,6 +610,7 @@ export function ChatPanel({
const parsed = JSON.parse(jsonText);
if (isCadPatchPayload(parsed)) return true;
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
@@ -608,6 +620,7 @@ export function ChatPanel({
const parsed = JSON.parse(trimmed);
if (isCadPatchPayload(parsed)) return true;
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
@@ -618,6 +631,7 @@ export function ChatPanel({
const parsed = JSON.parse(raw.slice(start, end + 1));
if (isCadPatchPayload(parsed)) return true;
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
@@ -842,6 +856,7 @@ export function ChatPanel({
const parsed = JSON.parse(jsonText);
if (parsed?.type === "cad_bom") bomEmitted = true;
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
onCodeAction?.(jsonText, 'cad');
};
@@ -902,6 +917,7 @@ export function ChatPanel({
try {
return JSON.parse(normalized.slice(start, end + 1));
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
return null;
@@ -919,6 +935,7 @@ export function ChatPanel({
masterSchemeJson = JSON.stringify(parsedMaster, null, 2);
}
} catch {
+ // No master scheme in this reply, which is the common case.
}
const imagesSheetMessages = buildCadImagesSheetMessages({ systemContent, planJson, svg2d, masterSchemeJson, outputLanguage: cadOutputLanguage });
@@ -970,6 +987,7 @@ export function ChatPanel({
});
}
} catch {
+ // allSettled cannot reject, so only a render error reaches here.
} finally {
setIsLoading(false);
abortControllerRef.current = null;
@@ -1051,6 +1069,7 @@ export function ChatPanel({
break;
}
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
@@ -1188,6 +1207,7 @@ export function ChatPanel({
try {
return JSON.parse(normalized.slice(start, end + 1));
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
return null;
@@ -1205,6 +1225,7 @@ export function ChatPanel({
masterSchemeJson = JSON.stringify(parsedMaster, null, 2);
}
} catch {
+ // No master scheme in this reply, which is the common case.
}
const imagesSheetMessages = buildCadImagesSheetMessages({
@@ -1330,6 +1351,7 @@ export function ChatPanel({
try {
parsed = JSON.parse(jsonText);
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
const isCadPatch = parsed?.type === "cad_patch" && parsed?.target === "2d_svg";
@@ -1349,9 +1371,15 @@ export function ChatPanel({
if (!cadPatchFound) {
const trimmed = String(toolFull || "").trim();
if (trimmed.startsWith("{")) {
+ let rawParsed: unknown = null;
try {
- const rawParsed = JSON.parse(trimmed);
- if (rawParsed?.type === "cad_patch" && rawParsed?.target === "2d_svg") {
+ rawParsed = JSON.parse(trimmed);
+ } catch {
+ // Not JSON at all; this fallback only guesses at the payload.
+ }
+
+ const patch = rawParsed as { type?: string; target?: string } | null;
+ if (patch?.type === "cad_patch" && patch?.target === "2d_svg") {
cadPatchFound = true;
const result = await runCodeAction(trimmed, "cad");
if (result.ok) {
@@ -1360,8 +1388,6 @@ export function ChatPanel({
if (normalizedAppliedSvg) appliedSvg = normalizedAppliedSvg;
}
if (!result.ok && result.retry) cadPatchRetryError = result.error || "Unknown error";
- }
- } catch {
}
}
}
@@ -1371,9 +1397,15 @@ export function ChatPanel({
const end = toolFull.lastIndexOf("}");
if (start >= 0 && end > start) {
const maybeJson = toolFull.slice(start, end + 1).trim();
+ let rawParsed: unknown = null;
try {
- const rawParsed = JSON.parse(maybeJson);
- if (rawParsed?.type === "cad_patch" && rawParsed?.target === "2d_svg") {
+ rawParsed = JSON.parse(maybeJson);
+ } catch {
+ // Not JSON at all; this fallback only guesses at the payload.
+ }
+
+ const patch = rawParsed as { type?: string; target?: string } | null;
+ if (patch?.type === "cad_patch" && patch?.target === "2d_svg") {
cadPatchFound = true;
const result = await runCodeAction(maybeJson, "cad");
if (result.ok) {
@@ -1382,8 +1414,6 @@ export function ChatPanel({
if (normalizedAppliedSvg) appliedSvg = normalizedAppliedSvg;
}
if (!result.ok && result.retry) cadPatchRetryError = result.error || "Unknown error";
- }
- } catch {
}
}
}
@@ -1706,6 +1736,7 @@ export function ChatPanel({
break;
}
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
@@ -1843,6 +1874,7 @@ export function ChatPanel({
try {
return JSON.parse(normalized.slice(start, end + 1));
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
}
return null;
@@ -1860,6 +1892,7 @@ export function ChatPanel({
masterSchemeJson = JSON.stringify(parsedMaster, null, 2);
}
} catch {
+ // No master scheme in this reply, which is the common case.
}
const imagesSheetMessages = buildCadImagesSheetMessages({
@@ -1985,6 +2018,7 @@ export function ChatPanel({
try {
parsed = JSON.parse(jsonText);
} catch {
+ // Not this payload; the caller falls through to the next shape.
}
const isCadPatch = parsed?.type === "cad_patch" && parsed?.target === "2d_svg";
@@ -2004,9 +2038,15 @@ export function ChatPanel({
if (!cadPatchFound) {
const trimmed = String(toolFull || "").trim();
if (trimmed.startsWith("{")) {
+ let rawParsed: unknown = null;
try {
- const rawParsed = JSON.parse(trimmed);
- if (rawParsed?.type === "cad_patch" && rawParsed?.target === "2d_svg") {
+ rawParsed = JSON.parse(trimmed);
+ } catch {
+ // Not JSON at all; this fallback only guesses at the payload.
+ }
+
+ const patch = rawParsed as { type?: string; target?: string } | null;
+ if (patch?.type === "cad_patch" && patch?.target === "2d_svg") {
cadPatchFound = true;
const result = await runCodeAction(trimmed, "cad");
if (result.ok) {
@@ -2015,8 +2055,6 @@ export function ChatPanel({
if (normalizedAppliedSvg) appliedSvg = normalizedAppliedSvg;
}
if (!result.ok && result.retry) cadPatchRetryError = result.error || "Unknown error";
- }
- } catch {
}
}
}
@@ -2026,9 +2064,15 @@ export function ChatPanel({
const end = toolFull.lastIndexOf("}");
if (start >= 0 && end > start) {
const maybeJson = toolFull.slice(start, end + 1).trim();
+ let rawParsed: unknown = null;
try {
- const rawParsed = JSON.parse(maybeJson);
- if (rawParsed?.type === "cad_patch" && rawParsed?.target === "2d_svg") {
+ rawParsed = JSON.parse(maybeJson);
+ } catch {
+ // Not JSON at all; this fallback only guesses at the payload.
+ }
+
+ const patch = rawParsed as { type?: string; target?: string } | null;
+ if (patch?.type === "cad_patch" && patch?.target === "2d_svg") {
cadPatchFound = true;
const result = await runCodeAction(maybeJson, "cad");
if (result.ok) {
@@ -2037,8 +2081,6 @@ export function ChatPanel({
if (normalizedAppliedSvg) appliedSvg = normalizedAppliedSvg;
}
if (!result.ok && result.retry) cadPatchRetryError = result.error || "Unknown error";
- }
- } catch {
}
}
}
diff --git a/client/workspaces/flow/lib/use-quota-manager.tsx b/client/workspaces/flow/lib/use-quota-manager.tsx
index 202765f..064790f 100644
--- a/client/workspaces/flow/lib/use-quota-manager.tsx
+++ b/client/workspaces/flow/lib/use-quota-manager.tsx
@@ -53,6 +53,7 @@ export function useQuotaManager(config: QuotaConfig): {
return true
}
} catch {
+ // Unreadable settings count as no key configured.
}
}
diff --git a/client/workspaces/ppt/PptWorkspace.tsx b/client/workspaces/ppt/PptWorkspace.tsx
index f6cf796..abeb61a 100644
--- a/client/workspaces/ppt/PptWorkspace.tsx
+++ b/client/workspaces/ppt/PptWorkspace.tsx
@@ -74,6 +74,7 @@ export function PptWorkspace() {
try {
localStorage.setItem(PPT_HISTORY_STORAGE_KEY, JSON.stringify(versionHistory));
} catch {
+ // A blocked localStorage only means the old history lingers.
}
}, [versionHistory]);
@@ -82,6 +83,7 @@ export function PptWorkspace() {
try {
localStorage.setItem(PPT_RETURN_STAGE_STORAGE_KEY, pptStage);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
}, [pptStage]);
@@ -98,10 +100,12 @@ export function PptWorkspace() {
try {
localStorage.removeItem(PPT_CHAT_STORAGE_KEY);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
try {
localStorage.removeItem(PPT_HISTORY_STORAGE_KEY);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
}, [pptStage]);
@@ -121,6 +125,7 @@ export function PptWorkspace() {
panel.resize("32%");
setIsChatCollapsed(false);
} catch {
+ // The panel is not mounted yet; the next toggle will find it.
}
}, 0);
return () => window.clearTimeout(timer);
@@ -242,6 +247,7 @@ export function PptWorkspace() {
try {
localStorage.removeItem(PPT_WORKSPACE_STORAGE_KEY);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
void pptStore.clear(PPT_STATE_KEY).catch((e) => {
console.error("Failed to clear persisted PPT workspace", e);
@@ -249,10 +255,12 @@ export function PptWorkspace() {
try {
localStorage.removeItem(PPT_CHAT_STORAGE_KEY);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
try {
localStorage.removeItem(PPT_HISTORY_STORAGE_KEY);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
setPptResetTick((x) => x + 1);
};
diff --git a/client/workspaces/ppt/canvas/PptCanvas.tsx b/client/workspaces/ppt/canvas/PptCanvas.tsx
index 7f0cd13..e8a0aa0 100644
--- a/client/workspaces/ppt/canvas/PptCanvas.tsx
+++ b/client/workspaces/ppt/canvas/PptCanvas.tsx
@@ -3292,6 +3292,7 @@ export function PptCanvas({
try {
localStorage.removeItem(PPT_WORKSPACE_STORAGE_KEY);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
void pptStore.clear(PPT_STATE_KEY).catch((e) => {
console.error("Failed to clear persisted PPT workspace", e);
diff --git a/client/workspaces/ppt/chat/ChatPanel.tsx b/client/workspaces/ppt/chat/ChatPanel.tsx
index ae2c5a9..aeafee0 100644
--- a/client/workspaces/ppt/chat/ChatPanel.tsx
+++ b/client/workspaces/ppt/chat/ChatPanel.tsx
@@ -189,6 +189,7 @@ const getPptTag = (slideId: string, title: string, kind: "outline" | "slide_imag
try {
localStorage.removeItem(storageKey);
} catch {
+ // A blocked localStorage only means the old history lingers.
}
setMessages([]);
setShowResetWarning(false);