@@ -3,27 +3,31 @@ import type { Properties } from "posthog-js";
33import renderToast from "roamjs-components/components/Toast" ;
44import { getVersionWithDate } from "~/utils/getVersion" ;
55import getCurrentUserDisplayName from "roamjs-components/queries/getCurrentUserDisplayName" ;
6+ import sendErrorEmail from "~/utils/sendErrorEmail" ;
67
78const internalError = ( {
89 error,
910 userMessage,
1011 type,
1112 context,
13+ sendEmail, // true by default
1214} : {
1315 error : unknown ;
1416 type ?: string ;
1517 userMessage ?: string ;
1618 context ?: Properties ;
19+ sendEmail ?: boolean ;
1720} ) : void => {
1821 if ( process . env . NODE_ENV === "development" ) {
1922 console . error ( error , context ) ;
2023 } else {
2124 const { version, buildDate } = getVersionWithDate ( ) ;
2225 const username = getCurrentUserDisplayName ( ) ;
2326 if ( username ) posthog . identify ( username ) ;
27+ type = type || "internal-error" ;
2428 context = {
2529 app : "Roam" ,
26- type : type || "internal-error" ,
30+ type,
2731 graphName : window . roamAlphaAPI ?. graph ?. name || "unknown" ,
2832 version : version || "-" ,
2933 buildDate : buildDate || "-" ,
@@ -41,6 +45,16 @@ const internalError = ({
4145 }
4246 }
4347 posthog . captureException ( error , context ) ;
48+ if ( sendEmail !== false ) {
49+ sendErrorEmail ( {
50+ // by now error is an Error but TS did not figure it out
51+ error : error as Error ,
52+ type,
53+ context,
54+ } ) . catch ( ( ) => {
55+ console . error ( "Could not send error email" , error , type , context ) ;
56+ } ) ;
57+ }
4458 }
4559 if ( userMessage !== undefined ) {
4660 renderToast ( {
0 commit comments