@@ -8,6 +8,7 @@ import React, {
88 useState ,
99 MouseEvent ,
1010} from "react" ;
11+ import { toast } from "react-toastify" ;
1112import {
1213 createClient ,
1314 getAstNodeInfo ,
@@ -65,6 +66,11 @@ export const Diagrams = (): JSX.Element => {
6566 ? await getFileInfo ( appCtx . projectFileId )
6667 : undefined ;
6768
69+ if ( ! fileInfoForClient ?. type ) {
70+ toast . error ( "File type is required to generate this diagram." ) ;
71+ return ;
72+ }
73+
6874 createClient ( appCtx . workspaceId , fileInfoForClient ?. type ) ;
6975
7076 const initDiagramInfo =
@@ -121,6 +127,11 @@ export const Diagrams = (): JSX.Element => {
121127 const parsedDiagram = parser . parseFromString ( diagram , "text/xml" ) ;
122128 const diagramSvg = parsedDiagram . getElementsByTagName ( "svg" ) [ 0 ] ;
123129
130+ if ( ! diagramSvg ) {
131+ toast . error ( "Failed to parse diagram or diagram is empty." ) ;
132+ return ;
133+ }
134+
124135 diagramSvg . style . height = "100%" ;
125136 diagramSvg . style . cursor = "pointer" ;
126137
@@ -154,6 +165,11 @@ export const Diagrams = (): JSX.Element => {
154165 ? await getFileInfo ( appCtx . projectFileId )
155166 : undefined ;
156167
168+ if ( ! fileInfoForClient ?. type ) {
169+ toast . error ( "File type is required to navigate to this diagram." ) ;
170+ return ;
171+ }
172+
157173 createClient ( appCtx . workspaceId , fileInfoForClient ?. type ) ;
158174
159175 const initDiagramInfo =
@@ -215,6 +231,11 @@ export const Diagrams = (): JSX.Element => {
215231 ) ;
216232 const diagramLegendSvg = parsedDiagramLegend . getElementsByTagName ( "svg" ) [ 0 ] ;
217233
234+ if ( ! diagramLegendSvg ) {
235+ toast . error ( "Failed to parse legend diagram or it is empty." ) ;
236+ return ;
237+ }
238+
218239 diagramLegendSvg . style . height = "100%" ;
219240 diagramLegendContainerRef . current . replaceChildren ( diagramLegendSvg ) ;
220241
0 commit comments