From 4a5cda8d34c44f711a9d734c974546503a3855a6 Mon Sep 17 00:00:00 2001 From: Dr Tracy Gardner Date: Sun, 29 Mar 2026 18:27:02 +0100 Subject: [PATCH] Fix remaining unused catch vars across repo examples --- api/csg.js | 24 ++++++++++++++++++------ api/material.js | 11 ++++++----- api/models.js | 7 ++++--- blocks/blocks.js | 16 ++++++++-------- blocks/materials.js | 6 ++++-- main/blocklyinit.js | 4 ++-- main/main.js | 2 +- scripts/run-api-tests.mjs | 13 ++++++++++--- ui/colourpicker.js | 6 ++++-- 9 files changed, 57 insertions(+), 32 deletions(-) diff --git a/api/csg.js b/api/csg.js index 412cf3172..ed07ce620 100644 --- a/api/csg.js +++ b/api/csg.js @@ -27,8 +27,11 @@ function prepareMeshForCSG(mesh) { try { mesh.convertToUnIndexedMesh(); mesh.forceSharedVertices(); - } catch (e) { - // Ignore errors, continue with other approaches + } catch (error) { + console.warn( + "[prepareMeshForCSG] Failed to convert mesh geometry:", + error, + ); } } @@ -77,8 +80,11 @@ function prepareMeshForCSG(mesh) { ) { meshesWithGeometry.push(child); } - } catch (e) { - // Ignore + } catch (error) { + console.warn( + "[prepareMeshForCSG] Failed to process child mesh geometry:", + error, + ); } }); } @@ -341,11 +347,12 @@ export const flockCSG = { if (mergedMesh) mergedMesh.dispose(); mergedMesh = null; } - } catch (e) { + } catch (error) { const emptyMeshes = flock.scene.meshes.filter( (m) => m.name === modelId && m.getTotalVertices() === 0, ); emptyMeshes.forEach((m) => m.dispose()); + console.warn("[mergeMeshes] CSG merge attempt failed:", error); csgSucceeded = false; } @@ -361,6 +368,10 @@ export const flockCSG = { true, ); } catch (mergeError) { + console.warn( + "[mergeMeshes] Mesh.MergeMeshes fallback failed:", + mergeError, + ); return null; } } @@ -504,7 +515,8 @@ export const flockCSG = { const tryCSG = (label, fn) => { try { return fn(); - } catch (e) { + } catch (error) { + console.warn(`[${label}] CSG operation failed:`, error); return null; } }; diff --git a/api/material.js b/api/material.js index 32602de4f..102cb96d8 100644 --- a/api/material.js +++ b/api/material.js @@ -83,7 +83,8 @@ export const flockMaterial = { const b = parseInt(matches[2]); const result = flock.rgbToHex(r, g, b); return result.toLowerCase(); - } catch (e) { + } catch (error) { + console.warn("Failed to parse color to hex; using default black:", error); return "#000000"; } }, @@ -871,7 +872,6 @@ export const flockMaterial = { }); }, setMaterialInternal(meshName, materials) { - return new Promise((resolve) => { flock.whenModelReady(meshName, (mesh) => { flock.applyMaterialToHierarchy(mesh, materials, { @@ -1263,9 +1263,10 @@ export const flockMaterial = { ), ); - const colorDark = colors.length >= 3 - ? flock.hexToRgb(flock.getColorFromString(colors[2])) - : { r: 0, g: 0, b: 0 }; + const colorDark = + colors.length >= 3 + ? flock.hexToRgb(flock.getColorFromString(colors[2])) + : { r: 0, g: 0, b: 0 }; shaderMaterial.setVector3( "darkColor", new flock.BABYLON.Vector3( diff --git a/api/models.js b/api/models.js index eb2654eb2..9fba169f1 100644 --- a/api/models.js +++ b/api/models.js @@ -394,7 +394,8 @@ export const flockModels = { }); return meshName; - } catch (e) { + } catch (error) { + console.warn("createObject failed; returning error id:", error); return "error_" + flock.scene.getUniqueId(); } }, @@ -425,8 +426,8 @@ export const flockModels = { container.textures = []; container.skeletons = []; container.animationGroups = []; - } catch (_) { - /* ignore */ + } catch (error) { + console.warn("releaseContainer cleanup failed:", error); } }, }; diff --git a/blocks/blocks.js b/blocks/blocks.js index bd0bfd777..94e75ea27 100644 --- a/blocks/blocks.js +++ b/blocks/blocks.js @@ -745,8 +745,8 @@ function adoptIsolatedDefaultVarsTo( if (remaining === 0) { try { workspace.deleteVariableById(vid); - } catch (_) { - /* ignore */ + } catch (error) { + console.warn("Failed to delete unreferenced variable by id:", error); } } } @@ -799,8 +799,11 @@ function normalizeVarNameAndIndex( workspace .getVariableMap() .renameVariable(model, `${prefix}${targetSuffix}`); - } catch (_) { - /* ignore rename failures */ + } catch (error) { + console.warn( + "Failed to rename variable to lowest available suffix:", + error, + ); } } @@ -870,10 +873,7 @@ export function ensureFreshVarOnDuplicate( if (!oldVarId) return false; const oldVarModel = ws.getVariableById(oldVarId); const { prefix: duplicatePrefix, suffix: duplicateSuffix } = - deriveVariableNameParts( - oldVarModel?.name, - variableNamePrefix, - ); + deriveVariableNameParts(oldVarModel?.name, variableNamePrefix); if (Number.isInteger(duplicateSuffix)) { const nextFromSource = duplicateSuffix + 1; diff --git a/blocks/materials.js b/blocks/materials.js index 61ac74f2b..d11595958 100644 --- a/blocks/materials.js +++ b/blocks/materials.js @@ -562,7 +562,8 @@ export function defineMaterialsBlocks() { const validatedVal = flock.getColorFromString(newVal) || "#000000"; this.sourceBlock_.setColour(validatedVal); return newVal; - } catch (e) { + } catch (error) { + console.warn("Failed to validate colour field value:", error); this.sourceBlock_.setColour("#000000"); return newVal; } @@ -573,7 +574,8 @@ export function defineMaterialsBlocks() { const initialVal = colorField.getValue(); const validatedVal = flock.getColorFromString(initialVal) || "#000000"; this.setColour(validatedVal); - } catch (e) { + } catch (error) { + console.warn("Failed to initialize colour block value:", error); this.setColour("#000000"); } }, diff --git a/main/blocklyinit.js b/main/blocklyinit.js index 79b16a0b3..8c753170b 100644 --- a/main/blocklyinit.js +++ b/main/blocklyinit.js @@ -655,7 +655,7 @@ export function createBlocklyWorkspace() { // Manually create a navigation-deferring toolbox class NavigationDeferringToolbox extends Blockly.Toolbox { - onKeyDown_(e) { + onKeyDown_() { return false; // Defer to keyboard navigation plugin } } @@ -682,7 +682,7 @@ export function createBlocklyWorkspace() { // Monkey-patch const toolbox = workspace.getToolbox(); - toolbox.onKeyDown_ = function (e) { + toolbox.onKeyDown_ = function () { return false; }; diff --git a/main/main.js b/main/main.js index 2ed7d36dd..fd7084213 100644 --- a/main/main.js +++ b/main/main.js @@ -423,7 +423,7 @@ window.onload = async function () { document .getElementById("info-details") - .addEventListener("toggle", function (e) { + .addEventListener("toggle", function () { if (this.open) { setTimeout(() => { const content = this.querySelector(".content"); diff --git a/scripts/run-api-tests.mjs b/scripts/run-api-tests.mjs index fa25f65d0..afffb6542 100644 --- a/scripts/run-api-tests.mjs +++ b/scripts/run-api-tests.mjs @@ -735,7 +735,11 @@ async function runTests(suiteId = "all") { window.apiCallLog.push( `[${timestamp}] ${methodName} (#${count}) ${argsStr}`, ); - } catch (e) { + } catch (error) { + console.warn( + "Failed to serialize API call arguments for logging:", + error, + ); window.apiCallLog.push( `[${timestamp}] ${methodName} (#${count})`, ); @@ -746,8 +750,11 @@ async function runTests(suiteId = "all") { }; })(prop, window._originalFlockMethods[prop]); } - } catch (e) { - // Skip properties that can't be accessed + } catch (error) { + console.warn( + "Skipping inaccessible flock property during instrumentation:", + error, + ); } } diff --git a/ui/colourpicker.js b/ui/colourpicker.js index 003af1e21..97e6d7924 100644 --- a/ui/colourpicker.js +++ b/ui/colourpicker.js @@ -1224,8 +1224,10 @@ class CustomColorPicker { const eyeDropper = new EyeDropper(); const result = await eyeDropper.open(); // resolves or throws on cancel this.setColor(result.sRGBHex); - } catch (e) { - // Cancel or error — just restore UI + } catch (error) { + if (error?.name !== "AbortError") { + console.warn("Eyedropper failed:", error); + } } finally { this.restoreUIAfterEyedropper(); }