replace panic! with internal_error! in compiler modules

This commit is contained in:
Jarl André Hübenthal 2023-05-02 18:33:15 +02:00
parent ba1f8ffe5f
commit e5eb5717ea
No known key found for this signature in database
11 changed files with 60 additions and 36 deletions

View file

@ -1,6 +1,7 @@
use crate::ident::{Ident, ModuleName};
use crate::module_err::{IdentIdNotFoundSnafu, ModuleIdNotFoundSnafu, ModuleResult};
use roc_collections::{SmallStringInterner, VecMap};
use roc_error_macros::internal_error;
use roc_ident::IdentStr;
use roc_region::all::Region;
use snafu::OptionExt;
@ -115,7 +116,7 @@ impl Symbol {
.module_ids
.get_name(self.module_id())
.unwrap_or_else(|| {
panic!(
internal_error!(
"module_string could not find IdentIds for module {:?} in {:?}",
self.module_id(),
interns
@ -128,7 +129,7 @@ impl Symbol {
.all_ident_ids
.get(&self.module_id())
.unwrap_or_else(|| {
panic!(
internal_error!(
"ident_string could not find IdentIds for module {:?} in {:?}",
self.module_id(),
interns
@ -136,7 +137,7 @@ impl Symbol {
});
ident_ids.get_name(self.ident_id()).unwrap_or_else(|| {
panic!(
internal_error!(
"ident_string's IdentIds did not contain an entry for {} in module {:?}",
self.ident_id().0,
self.module_id()
@ -267,9 +268,10 @@ impl Interns {
pub fn module_name(&self, module_id: ModuleId) -> &ModuleName {
self.module_ids.get_name(module_id).unwrap_or_else(|| {
panic!(
internal_error!(
"Unable to find interns entry for module_id {:?} in Interns {:?}",
module_id, self
module_id,
self
)
})
}
@ -281,16 +283,18 @@ impl Interns {
Some(ident_ids) => match ident_ids.get_id(ident.as_str()) {
Some(ident_id) => Symbol::new(module_id, ident_id),
None => {
panic!(
internal_error!(
"Interns::symbol could not find ident entry for {:?} for module {:?}",
ident, module_id
ident,
module_id
);
}
},
None => {
panic!(
internal_error!(
"Interns::symbol could not find entry for module {:?} in Interns {:?}",
module_id, self
module_id,
self
);
}
}
@ -374,7 +378,7 @@ impl ModuleId {
interns
.module_ids
.get_name(self)
.unwrap_or_else(|| panic!("Could not find ModuleIds for {:?}", self))
.unwrap_or_else(|| internal_error!("Could not find ModuleIds for {:?}", self))
}
}
@ -398,9 +402,10 @@ impl fmt::Debug for ModuleId {
match names.try_get(self.to_zero_indexed()) {
Some(str_ref) => write!(f, "{}", str_ref),
None => {
panic!(
internal_error!(
"Could not find a Debug name for module ID {} in {:?}",
self.0, names,
self.0,
names,
);
}
}
@ -832,7 +837,7 @@ macro_rules! define_builtins {
if cfg!(debug_assertions) {
match LENGTH_CHECK {
None => (),
Some((given, expected)) => panic!(
Some((given, expected)) => internal_error!(
"Symbol {} : {} should have index {} based on the insertion order, try {} : {} instead",
given, NAMES[expected], expected, expected, NAMES[expected],
),
@ -842,7 +847,7 @@ macro_rules! define_builtins {
if cfg!(debug_assertions) {
match DUPLICATE_CHECK {
None => (),
Some((first, second)) => panic!(
Some((first, second)) => internal_error!(
"Symbol {} : {} is duplicated at position {}, try removing the duplicate",
first, NAMES[first], second
),