@@ -57,7 +57,7 @@ import { MAX_WIDTH } from "./Tldraw";
5757import getBlockProps from "~/utils/getBlockProps" ;
5858import setBlockProps from "~/utils/setBlockProps" ;
5959import { measureCanvasNodeText } from "~/utils/measureCanvasNodeText" ;
60- import sendErrorEmail from "~/utils/sendErrorEmail " ;
60+ import internalError from "~/utils/internalError " ;
6161
6262export type ClipboardPage = {
6363 uid : string ;
@@ -79,21 +79,6 @@ const ClipboardContext = createContext<ClipboardContextValue | null>(null);
7979
8080const CLIPBOARD_PROP_KEY = "pages" ;
8181
82- const toError = ( error : unknown , fallbackMessage : string ) : Error => {
83- if ( error instanceof Error ) {
84- return error ;
85- }
86- if ( typeof error === "string" ) {
87- return new Error ( error ) ;
88- }
89- try {
90- const serialized = JSON . stringify ( error ) ;
91- return new Error ( serialized || fallbackMessage ) ;
92- } catch {
93- return new Error ( fallbackMessage ) ;
94- }
95- } ;
96-
9782const getOrCreateClipboardBlock = async (
9883 canvasPageTitle : string ,
9984 userUid : string ,
@@ -155,11 +140,13 @@ export const ClipboardProvider = ({
155140 try {
156141 const userUid = getCurrentUserUid ( ) ;
157142 if ( ! userUid ) {
158- sendErrorEmail ( {
143+ internalError ( {
159144 error : new Error ( "Missing current user UID" ) ,
160145 type : "Canvas Clipboard: Missing current user UID" ,
161- context : { canvasPageTitle } ,
162- } ) . catch ( ( ) => { } ) ;
146+ context : {
147+ canvasPageTitle,
148+ } ,
149+ } ) ;
163150 setIsInitialized ( true ) ;
164151 return ;
165152 }
@@ -179,13 +166,12 @@ export const ClipboardProvider = ({
179166 ) {
180167 setPages ( storedPages as ClipboardPage [ ] ) ;
181168 }
182- } catch ( e ) {
183- const normalizedError = toError ( e , "Failed to initialize clipboard" ) ;
184- sendErrorEmail ( {
185- error : normalizedError ,
169+ } catch ( error ) {
170+ internalError ( {
171+ error,
186172 type : "Canvas Clipboard: Failed to initialize" ,
187173 context : { canvasPageTitle } ,
188- } ) . catch ( ( ) => { } ) ;
174+ } ) ;
189175 } finally {
190176 setIsInitialized ( true ) ;
191177 }
@@ -201,13 +187,12 @@ export const ClipboardProvider = ({
201187 setBlockProps ( clipboardBlockUid , {
202188 [ CLIPBOARD_PROP_KEY ] : pages ,
203189 } ) ;
204- } catch ( e ) {
205- const normalizedError = toError ( e , "Failed to persist clipboard state" ) ;
206- sendErrorEmail ( {
207- error : normalizedError ,
190+ } catch ( error ) {
191+ internalError ( {
192+ error,
208193 type : "Canvas Clipboard: Failed to persist state" ,
209194 context : { clipboardBlockUid, pageCount : pages . length } ,
210- } ) . catch ( ( ) => { } ) ;
195+ } ) ;
211196 }
212197 } , [ pages , clipboardBlockUid , isInitialized ] ) ;
213198
@@ -287,8 +272,8 @@ const AddPageModal = ({ isOpen, onClose, onConfirm }: AddPageModalProps) => {
287272 // eslint-disable-next-line @typescript-eslint/await-thenable
288273 const raw = await window . roamAlphaAPI . data . backend . q (
289274 `
290- [:find ?text ?uid
291- :where
275+ [:find ?text ?uid
276+ :where
292277 [?e :node/title ?text]
293278 [?e :block/uid ?uid]]` ,
294279 ) ;
@@ -447,15 +432,11 @@ const ClipboardPageSection = ({
447432 ) ;
448433 setDiscourseNodes ( nodes ) ;
449434 } catch ( error ) {
450- const normalizedError = toError (
435+ internalError ( {
451436 error,
452- "Failed to fetch discourse nodes" ,
453- ) ;
454- sendErrorEmail ( {
455- error : normalizedError ,
456437 type : "Canvas Clipboard: Failed to fetch discourse nodes" ,
457438 context : { pageTitle : page . text } ,
458- } ) . catch ( ( ) => { } ) ;
439+ } ) ;
459440 setDiscourseNodes ( [ ] ) ;
460441 } finally {
461442 setIsLoading ( false ) ;
@@ -610,11 +591,11 @@ const ClipboardPageSection = ({
610591
611592 const nodeType = findDiscourseNode ( node . uid ) ;
612593 if ( ! nodeType ) {
613- sendErrorEmail ( {
614- error : new Error ( "Node type not found" ) ,
594+ internalError ( {
595+ error : new Error ( "Canvas Clipboard: Node type not found" ) ,
615596 type : "Canvas Clipboard: Node type not found" ,
616597 context : { uid : node . uid } ,
617- } ) . catch ( ( ) => { } ) ;
598+ } ) ;
618599 return ;
619600 }
620601
0 commit comments