From 1cc77e5e3abec8be1bd28ff494d241a201cd93c6 Mon Sep 17 00:00:00 2001 From: NiseVoid Date: Sat, 3 Aug 2024 11:28:51 +0200 Subject: [PATCH] Replace unwrap in error handling (#93) I ran accross a case where instead of a warning I got an unwrap in error handling. Two cases didn't seem to use `unwrap_or(0..0)` like all the others in this function. The errors will get slightly weird when it's missing but at least it won't cause crashes and the user has some idea of what is wrong --- src/compose/error.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compose/error.rs b/src/compose/error.rs index 7a98ed9..e2c9021 100644 --- a/src/compose/error.rs +++ b/src/compose/error.rs @@ -195,7 +195,7 @@ impl ComposerError { .map(|(span, desc)| { trace!( "mapping span {:?} -> {:?}", - span.to_range().unwrap(), + span.to_range().unwrap_or(0..0), map_span(span.to_range().unwrap_or(0..0)) ); Label::primary((), map_span(span.to_range().unwrap_or(0..0))) @@ -217,7 +217,8 @@ impl ComposerError { ComposerErrorInner::WgslParseError(e) => ( e.labels() .map(|(range, msg)| { - Label::primary((), map_span(range.to_range().unwrap())).with_message(msg) + Label::primary((), map_span(range.to_range().unwrap_or(0..0))) + .with_message(msg) }) .collect(), vec![e.message().to_owned()],