@@ -117,7 +117,7 @@ export async function saveInstanceConfig(): Promise<void> {
117117 showError ( undefined ) ;
118118
119119 try {
120- const instName = selectInstance . options [ selectInstance . selectedIndex ] . value ;
120+ const instName = selectInstance . options [ selectInstance . selectedIndex ] ? .value ;
121121 const config = JSON . parse ( editor . getValue ( ) ) ;
122122 const msg : Partial < UpdateInstanceConfigMessage > = {
123123 config : config ,
@@ -133,7 +133,7 @@ export async function saveInstanceConfig(): Promise<void> {
133133// Delete button
134134export async function deleteInstance ( ) : Promise < void > {
135135 const msg : Partial < DeleteServiceInstanceMessage > = {
136- instanceName : selectInstance . options [ selectInstance . selectedIndex ] . value ,
136+ instanceName : selectInstance . options [ selectInstance . selectedIndex ] ? .value ,
137137 } ;
138138
139139 const deleted = await sendAuthenticatedMessage ( "deleteServiceInstance" , msg ) ;
@@ -146,15 +146,22 @@ export async function deleteInstance(): Promise<void> {
146146
147147// Create button
148148export async function createInstance ( ) : Promise < void > {
149- const service = selectService . options [ selectService . options . selectedIndex ] . value ;
149+ showError ( undefined ) ;
150+ const service = selectService . options [ selectService . options . selectedIndex ] ?. value ;
150151 const name = inputInstanceName . value ;
151152
152153 const msg : Partial < CreateServiceInstanceMessage > = {
153154 serviceType : service ,
154155 instanceName : name ,
155156 } ;
156157
157- await sendAuthenticatedMessage ( "createServiceInstance" , msg ) ;
158+ try {
159+ await sendAuthenticatedMessage ( "createServiceInstance" , msg ) ;
160+ } catch ( e ) {
161+ showError ( e ) ;
162+ return ;
163+ }
164+
158165 // Give the browser some time to create the new instance select option and to add them to the DOM
159166 setTimeout ( ( ) => {
160167 selectServiceInstance ( name ) ;
@@ -203,7 +210,7 @@ function renderInstances() {
203210function selectServiceInstance ( instanceName : string ) {
204211 for ( let i = 0 ; i < selectInstance . options . length ; i ++ ) {
205212 const opt = selectInstance . options [ i ] ;
206- if ( opt . value === instanceName ) {
213+ if ( opt ? .value === instanceName ) {
207214 selectInstance . selectedIndex = i ;
208215 onInstanceSelectChange ( instanceName ) ;
209216 break ;
0 commit comments