@@ -158,9 +158,18 @@ class GraphServer extends GraphLoadSave {
158158 } ) ;
159159 }
160160
161+ getCurrentGraphName ( ) {
162+ const currentGraph = this . superState . graphs [ this . superState . curGraphIndex ] ;
163+ if ( ! currentGraph || typeof currentGraph . fileName !== 'string' || ! currentGraph . fileName . trim ( ) ) {
164+ toast . error ( 'Open a GraphML file before using server actions.' ) ;
165+ return null ;
166+ }
167+ return currentGraph . fileName . trim ( ) . split ( '.' ) [ 0 ] ;
168+ }
169+
161170 build ( ) {
162- const graphName = this . superState . graphs [
163- this . superState . curGraphIndex ] . fileName . split ( '.' ) [ 0 ] ;
171+ const graphName = this . getCurrentGraphName ( ) ;
172+ if ( ! graphName ) return ;
164173 const url = `${ EXECUTION_ENGINE_URL } /build/${ this . superState . uploadedDirName } `
165174 + `?fetch=${ graphName } &unlock=${ this . superState . unlockCheck } `
166175 + `&docker=${ this . superState . dockerCheck } `
@@ -175,26 +184,26 @@ class GraphServer extends GraphLoadSave {
175184 }
176185
177186 debug ( ) {
178- const graphName = this . superState . graphs [
179- this . superState . curGraphIndex ] . fileName . split ( '.' ) [ 0 ] ;
187+ const graphName = this . getCurrentGraphName ( ) ;
188+ if ( ! graphName ) return ;
180189 const url = `${ EXECUTION_ENGINE_URL } /debug/${ graphName } ` ;
181190 this . serverAction ( 'post' , url , {
182191 built : false , ran : false , debugged : false , cleared : true , stopped : true , destroyed : true ,
183192 } ) ;
184193 }
185194
186195 run ( ) {
187- const graphName = this . superState . graphs [
188- this . superState . curGraphIndex ] . fileName . split ( '.' ) [ 0 ] ;
196+ const graphName = this . getCurrentGraphName ( ) ;
197+ if ( ! graphName ) return ;
189198 const url = `${ EXECUTION_ENGINE_URL } /run/${ graphName } ` ;
190199 this . serverAction ( 'post' , url , {
191200 built : false , ran : false , debugged : false , cleared : true , stopped : true , destroyed : true ,
192201 } ) ;
193202 }
194203
195204 clear ( ) {
196- const graphName = this . superState . graphs [
197- this . superState . curGraphIndex ] . fileName . split ( '.' ) [ 0 ] ;
205+ const graphName = this . getCurrentGraphName ( ) ;
206+ if ( ! graphName ) return ;
198207 const url = `${ EXECUTION_ENGINE_URL } /clear/${ graphName } `
199208 + `?unlock=${ this . superState . unlockCheck } `
200209 + `&maxtime=${ this . superState . maxTime } `
@@ -205,17 +214,17 @@ class GraphServer extends GraphLoadSave {
205214 }
206215
207216 stop ( ) {
208- const graphName = this . superState . graphs [
209- this . superState . curGraphIndex ] . fileName . split ( '.' ) [ 0 ] ;
217+ const graphName = this . getCurrentGraphName ( ) ;
218+ if ( ! graphName ) return ;
210219 const url = `${ EXECUTION_ENGINE_URL } /stop/${ graphName } ` ;
211220 this . serverAction ( 'post' , url , {
212221 built : false , ran : false , debugged : false , cleared : true , stopped : false , destroyed : true ,
213222 } ) ;
214223 }
215224
216225 destroy ( ) {
217- const graphName = this . superState . graphs [
218- this . superState . curGraphIndex ] . fileName . split ( '.' ) [ 0 ] ;
226+ const graphName = this . getCurrentGraphName ( ) ;
227+ if ( ! graphName ) return ;
219228 const url = `${ EXECUTION_ENGINE_URL } /destroy/${ graphName } ` ;
220229 this . serverAction ( 'delete' , url , {
221230 built : true , ran : false , debugged : false , cleared : false , stopped : false , destroyed : false ,
0 commit comments