From 6b888775bfff6915f0bf5c472b1703be6d693044 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Thu, 18 Dec 2025 10:33:21 -0500 Subject: [PATCH 1/3] ENG-1149 try-catch when getRelationData fails --- apps/roam/src/utils/getRelationData.ts | 69 +++++++++++++++----------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/apps/roam/src/utils/getRelationData.ts b/apps/roam/src/utils/getRelationData.ts index 199110f72..6fb12d502 100644 --- a/apps/roam/src/utils/getRelationData.ts +++ b/apps/roam/src/utils/getRelationData.ts @@ -2,6 +2,7 @@ import fireQuery from "./fireQuery"; import getDiscourseNodes from "./getDiscourseNodes"; import getDiscourseRelations from "./getDiscourseRelations"; import type { DiscourseRelation } from "./getDiscourseRelations"; +import internalError from "./internalError"; // lifted from getExportTypes @@ -17,36 +18,44 @@ export const getRelationDataUtil = async ( s.triples.some((t) => t[2] === "destination"), ) .flatMap((s) => { - const sourceLabel = nodeLabelByType[s.source]; - const targetLabel = nodeLabelByType[s.destination]; - return !sourceLabel || !targetLabel - ? [] - : fireQuery({ - returnNode: sourceLabel, - conditions: [ - { - relation: s.label, - source: sourceLabel, - target: targetLabel, - uid: s.id, - type: "clause", - }, - ], - selections: [ - { - uid: window.roamAlphaAPI.util.generateUID(), - text: `node:${targetLabel}`, - label: "target", - }, - ], - }).then((results) => - results.map((result) => ({ - source: result.uid, - target: result["target-uid"], - relUid: s.id, - label: s.label, - })), - ); + try { + const sourceLabel = nodeLabelByType[s.source]; + const targetLabel = nodeLabelByType[s.destination]; + return !sourceLabel || !targetLabel + ? [] + : fireQuery({ + returnNode: sourceLabel, + conditions: [ + { + relation: s.label, + source: sourceLabel, + target: targetLabel, + uid: s.id, + type: "clause", + }, + ], + selections: [ + { + uid: window.roamAlphaAPI.util.generateUID(), + text: `node:${targetLabel}`, + label: "target", + }, + ], + }).then((results) => + results.map((result) => ({ + source: result.uid, + target: result["target-uid"], + relUid: s.id, + label: s.label, + })), + ); + } catch (error) { + internalError({ + error, + type: "Get relation data", + userMessage: `Could not find relations of type ${s.label}`, + }); + } }), ).then((r) => r.flat()); From 20612bb5811084ac171e3d20f922433d771846c1 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Thu, 18 Dec 2025 10:37:35 -0500 Subject: [PATCH 2/3] return value on catch --- apps/roam/src/utils/getRelationData.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/roam/src/utils/getRelationData.ts b/apps/roam/src/utils/getRelationData.ts index 6fb12d502..73a19cb1b 100644 --- a/apps/roam/src/utils/getRelationData.ts +++ b/apps/roam/src/utils/getRelationData.ts @@ -55,6 +55,7 @@ export const getRelationDataUtil = async ( type: "Get relation data", userMessage: `Could not find relations of type ${s.label}`, }); + return []; } }), ).then((r) => r.flat()); From 25c7517c56f72d198d546dc9cd1079fbbd24fc92 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Parent Date: Thu, 18 Dec 2025 13:47:08 -0500 Subject: [PATCH 3/3] catch the promise, not above it --- apps/roam/src/utils/getRelationData.ts | 66 +++++++++++++------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/apps/roam/src/utils/getRelationData.ts b/apps/roam/src/utils/getRelationData.ts index 73a19cb1b..b1311d75d 100644 --- a/apps/roam/src/utils/getRelationData.ts +++ b/apps/roam/src/utils/getRelationData.ts @@ -18,45 +18,45 @@ export const getRelationDataUtil = async ( s.triples.some((t) => t[2] === "destination"), ) .flatMap((s) => { - try { - const sourceLabel = nodeLabelByType[s.source]; - const targetLabel = nodeLabelByType[s.destination]; - return !sourceLabel || !targetLabel - ? [] - : fireQuery({ - returnNode: sourceLabel, - conditions: [ - { - relation: s.label, - source: sourceLabel, - target: targetLabel, - uid: s.id, - type: "clause", - }, - ], - selections: [ - { - uid: window.roamAlphaAPI.util.generateUID(), - text: `node:${targetLabel}`, - label: "target", - }, - ], - }).then((results) => + const sourceLabel = nodeLabelByType[s.source]; + const targetLabel = nodeLabelByType[s.destination]; + return !sourceLabel || !targetLabel + ? [] + : fireQuery({ + returnNode: sourceLabel, + conditions: [ + { + relation: s.label, + source: sourceLabel, + target: targetLabel, + uid: s.id, + type: "clause", + }, + ], + selections: [ + { + uid: window.roamAlphaAPI.util.generateUID(), + text: `node:${targetLabel}`, + label: "target", + }, + ], + }) + .then((results) => results.map((result) => ({ source: result.uid, target: result["target-uid"], relUid: s.id, label: s.label, })), - ); - } catch (error) { - internalError({ - error, - type: "Get relation data", - userMessage: `Could not find relations of type ${s.label}`, - }); - return []; - } + ) + .catch((error) => { + internalError({ + error, + type: "Get relation data", + userMessage: `Could not find relations of type ${s.label}`, + }); + return []; + }); }), ).then((r) => r.flat());