@@ -123,7 +123,10 @@ impl LayoutMessageHandler {
123
123
let callback_message = match action {
124
124
WidgetValueAction :: Commit => ( breadcrumb_trail_buttons. on_commit . callback ) ( & ( ) ) ,
125
125
WidgetValueAction :: Update => {
126
- let update_value = value. as_u64 ( ) . expect ( "BreadcrumbTrailButtons update was not of type: u64" ) ;
126
+ let Some ( update_value) = value. as_u64 ( ) else {
127
+ error ! ( "BreadcrumbTrailButtons update was not of type: u64" ) ;
128
+ return ;
129
+ } ;
127
130
( breadcrumb_trail_buttons. on_update . callback ) ( & update_value)
128
131
}
129
132
} ;
@@ -133,7 +136,10 @@ impl LayoutMessageHandler {
133
136
let callback_message = match action {
134
137
WidgetValueAction :: Commit => ( checkbox_input. on_commit . callback ) ( & ( ) ) ,
135
138
WidgetValueAction :: Update => {
136
- let update_value = value. as_bool ( ) . expect ( "CheckboxInput update was not of type: bool" ) ;
139
+ let Some ( update_value) = value. as_bool ( ) else {
140
+ error ! ( "CheckboxInput update was not of type: bool" ) ;
141
+ return ;
142
+ } ;
137
143
checkbox_input. checked = update_value;
138
144
( checkbox_input. on_update . callback ) ( checkbox_input)
139
145
}
@@ -208,7 +214,10 @@ impl LayoutMessageHandler {
208
214
let callback_message = match action {
209
215
WidgetValueAction :: Commit => ( curve_input. on_commit . callback ) ( & ( ) ) ,
210
216
WidgetValueAction :: Update => {
211
- let curve = serde_json:: from_value ( value) . expect ( "CurveInput event data could not be deserialized" ) ;
217
+ let Some ( curve) = serde_json:: from_value ( value) . ok ( ) else {
218
+ error ! ( "CurveInput event data could not be deserialized" ) ;
219
+ return ;
220
+ } ;
212
221
curve_input. value = curve;
213
222
( curve_input. on_update . callback ) ( curve_input)
214
223
}
@@ -219,13 +228,27 @@ impl LayoutMessageHandler {
219
228
Widget :: DropdownInput ( dropdown_input) => {
220
229
let callback_message = match action {
221
230
WidgetValueAction :: Commit => {
222
- let update_value = value. as_u64 ( ) . unwrap_or_else ( || panic ! ( "DropdownInput commit was not of type `u64`, found {value:?}" ) ) ;
223
- ( dropdown_input. entries . iter ( ) . flatten ( ) . nth ( update_value as usize ) . unwrap ( ) . on_commit . callback ) ( & ( ) )
231
+ let Some ( update_value) = value. as_u64 ( ) else {
232
+ error ! ( "DropdownInput commit was not of type `u64`, found {value:?}" ) ;
233
+ return ;
234
+ } ;
235
+ let Some ( entry) = dropdown_input. entries . iter ( ) . flatten ( ) . nth ( update_value as usize ) else {
236
+ error ! ( "DropdownInput commit was not able to find entry for index {update_value}" ) ;
237
+ return ;
238
+ } ;
239
+ ( entry. on_commit . callback ) ( & ( ) )
224
240
}
225
241
WidgetValueAction :: Update => {
226
- let update_value = value. as_u64 ( ) . unwrap_or_else ( || panic ! ( "DropdownInput update was not of type `u64`, found {value:?}" ) ) ;
242
+ let Some ( update_value) = value. as_u64 ( ) else {
243
+ error ! ( "DropdownInput update was not of type `u64`, found {value:?}" ) ;
244
+ return ;
245
+ } ;
227
246
dropdown_input. selected_index = Some ( update_value as u32 ) ;
228
- ( dropdown_input. entries . iter ( ) . flatten ( ) . nth ( update_value as usize ) . unwrap ( ) . on_update . callback ) ( & ( ) )
247
+ let Some ( entry) = dropdown_input. entries . iter ( ) . flatten ( ) . nth ( update_value as usize ) else {
248
+ error ! ( "DropdownInput update was not able to find entry for index {update_value}" ) ;
249
+ return ;
250
+ } ;
251
+ ( entry. on_update . callback ) ( & ( ) )
229
252
}
230
253
} ;
231
254
@@ -235,12 +258,27 @@ impl LayoutMessageHandler {
235
258
let callback_message = match action {
236
259
WidgetValueAction :: Commit => ( font_input. on_commit . callback ) ( & ( ) ) ,
237
260
WidgetValueAction :: Update => {
238
- let update_value = value. as_object ( ) . expect ( "FontInput update was not of type: object" ) ;
239
- let font_family_value = update_value. get ( "fontFamily" ) . expect ( "FontInput update does not have a fontFamily" ) ;
240
- let font_style_value = update_value. get ( "fontStyle" ) . expect ( "FontInput update does not have a fontStyle" ) ;
261
+ let Some ( update_value) = value. as_object ( ) else {
262
+ error ! ( "FontInput update was not of type: object" ) ;
263
+ return ;
264
+ } ;
265
+ let Some ( font_family_value) = update_value. get ( "fontFamily" ) else {
266
+ error ! ( "FontInput update does not have a fontFamily" ) ;
267
+ return ;
268
+ } ;
269
+ let Some ( font_style_value) = update_value. get ( "fontStyle" ) else {
270
+ error ! ( "FontInput update does not have a fontStyle" ) ;
271
+ return ;
272
+ } ;
241
273
242
- let font_family = font_family_value. as_str ( ) . expect ( "FontInput update fontFamily was not of type: string" ) ;
243
- let font_style = font_style_value. as_str ( ) . expect ( "FontInput update fontStyle was not of type: string" ) ;
274
+ let Some ( font_family) = font_family_value. as_str ( ) else {
275
+ error ! ( "FontInput update fontFamily was not of type: string" ) ;
276
+ return ;
277
+ } ;
278
+ let Some ( font_style) = font_style_value. as_str ( ) else {
279
+ error ! ( "FontInput update fontStyle was not of type: string" ) ;
280
+ return ;
281
+ } ;
244
282
245
283
font_input. font_family = font_family. into ( ) ;
246
284
font_input. font_style = font_style. into ( ) ;
@@ -285,7 +323,10 @@ impl LayoutMessageHandler {
285
323
responses. add ( callback_message) ;
286
324
}
287
325
WidgetValueAction :: Update => {
288
- let value = value. as_str ( ) . expect ( "NodeCatalog update was not of type String" ) . to_string ( ) ;
326
+ let Some ( value) = value. as_str ( ) . map ( |s| s. to_string ( ) ) else {
327
+ error ! ( "NodeCatalog update was not of type String" ) ;
328
+ return ;
329
+ } ;
289
330
let callback_message = ( node_type_input. on_update . callback ) ( & value) ;
290
331
responses. add ( callback_message) ;
291
332
}
@@ -296,8 +337,11 @@ impl LayoutMessageHandler {
296
337
responses. add ( callback_message) ;
297
338
}
298
339
WidgetValueAction :: Update => match value {
299
- Value :: Number ( num) => {
300
- let update_value = num. as_f64 ( ) . unwrap ( ) ;
340
+ Value :: Number ( ref num) => {
341
+ let Some ( update_value) = num. as_f64 ( ) else {
342
+ error ! ( "NumberInput update was not of type: f64, found {value:?}" ) ;
343
+ return ;
344
+ } ;
301
345
number_input. value = Some ( update_value) ;
302
346
let callback_message = ( number_input. on_update . callback ) ( number_input) ;
303
347
responses. add ( callback_message) ;
@@ -323,7 +367,10 @@ impl LayoutMessageHandler {
323
367
let callback_message = match action {
324
368
WidgetValueAction :: Commit => ( reference_point_input. on_commit . callback ) ( & ( ) ) ,
325
369
WidgetValueAction :: Update => {
326
- let update_value = value. as_str ( ) . expect ( "ReferencePointInput update was not of type: u64" ) ;
370
+ let Some ( update_value) = value. as_str ( ) else {
371
+ error ! ( "ReferencePointInput update was not of type: u64" ) ;
372
+ return ;
373
+ } ;
327
374
reference_point_input. value = update_value. into ( ) ;
328
375
( reference_point_input. on_update . callback ) ( reference_point_input)
329
376
}
@@ -333,7 +380,10 @@ impl LayoutMessageHandler {
333
380
}
334
381
Widget :: PopoverButton ( _) => { }
335
382
Widget :: RadioInput ( radio_input) => {
336
- let update_value = value. as_u64 ( ) . expect ( "RadioInput update was not of type: u64" ) ;
383
+ let Some ( update_value) = value. as_u64 ( ) else {
384
+ error ! ( "RadioInput update was not of type: u64" ) ;
385
+ return ;
386
+ } ;
337
387
radio_input. selected_index = Some ( update_value as u32 ) ;
338
388
let callback_message = match action {
339
389
WidgetValueAction :: Commit => ( radio_input. entries [ update_value as usize ] . on_commit . callback ) ( & ( ) ) ,
@@ -347,7 +397,10 @@ impl LayoutMessageHandler {
347
397
let callback_message = match action {
348
398
WidgetValueAction :: Commit => ( text_area_input. on_commit . callback ) ( & ( ) ) ,
349
399
WidgetValueAction :: Update => {
350
- let update_value = value. as_str ( ) . expect ( "TextAreaInput update was not of type: string" ) ;
400
+ let Some ( update_value) = value. as_str ( ) else {
401
+ error ! ( "TextAreaInput update was not of type: string" ) ;
402
+ return ;
403
+ } ;
351
404
text_area_input. value = update_value. into ( ) ;
352
405
( text_area_input. on_update . callback ) ( text_area_input)
353
406
}
@@ -367,7 +420,10 @@ impl LayoutMessageHandler {
367
420
let callback_message = match action {
368
421
WidgetValueAction :: Commit => ( text_input. on_commit . callback ) ( & ( ) ) ,
369
422
WidgetValueAction :: Update => {
370
- let update_value = value. as_str ( ) . expect ( "TextInput update was not of type: string" ) ;
423
+ let Some ( update_value) = value. as_str ( ) else {
424
+ error ! ( "TextInput update was not of type: string" ) ;
425
+ return ;
426
+ } ;
371
427
text_input. value = update_value. into ( ) ;
372
428
( text_input. on_update . callback ) ( text_input)
373
429
}
@@ -411,10 +467,11 @@ impl LayoutMessageHandler {
411
467
self . layouts [ layout_target as usize ] = new_layout;
412
468
413
469
// Update the UI
414
- responses. add ( FrontendMessage :: UpdateMenuBarLayout {
415
- layout_target,
416
- layout : self . layouts [ layout_target as usize ] . clone ( ) . unwrap_menu_layout ( action_input_mapping) . layout ,
417
- } ) ;
470
+ let Some ( layout) = self . layouts [ layout_target as usize ] . clone ( ) . as_menu_layout ( action_input_mapping) . map ( |x| x. layout ) else {
471
+ error ! ( "Called unwrap_menu_layout on a widget layout" ) ;
472
+ return ;
473
+ } ;
474
+ responses. add ( FrontendMessage :: UpdateMenuBarLayout { layout_target, layout } ) ;
418
475
}
419
476
}
420
477
}
0 commit comments