cleanup unwrap

This commit is contained in:
Anton-4 2021-10-15 19:01:41 +02:00
parent d3f2b95f7a
commit e003725f21
13 changed files with 110 additions and 55 deletions

View file

@ -4,6 +4,7 @@
pub mod ident;
pub mod low_level;
pub mod module_err;
pub mod operator;
pub mod symbol;

View file

@ -0,0 +1,18 @@
use snafu::{Backtrace, Snafu};
#[derive(Debug, Snafu)]
#[snafu(visibility(pub))]
pub enum ModuleError {
#[snafu(display(
"ModuleIdNotFound: I could not find the ModuleId {} in Interns.all_ident_ids: {}.",
module_id,
all_ident_ids
))]
ModuleIdNotFound {
module_id: String,
all_ident_ids: String,
backtrace: Backtrace,
},
}
pub type ModuleResult<T, E = ModuleError> = std::result::Result<T, E>;

View file

@ -1,7 +1,9 @@
use crate::ident::{Ident, ModuleName};
use crate::module_err::{ModuleIdNotFound, ModuleResult};
use roc_collections::all::{default_hasher, MutMap, SendMap};
use roc_ident::IdentStr;
use roc_region::all::Region;
use snafu::OptionExt;
use std::collections::HashMap;
use std::{fmt, u32};
@ -253,6 +255,15 @@ impl Interns {
pub fn from_index(module_id: ModuleId, ident_id: u32) -> Symbol {
Symbol::new(module_id, IdentId(ident_id))
}
pub fn get_module_ident_ids(&self, module_id: &ModuleId) -> ModuleResult<&IdentIds> {
self.all_ident_ids
.get(module_id)
.with_context(|| ModuleIdNotFound {
module_id: format!("{:?}", module_id),
all_ident_ids: format!("{:?}", self.all_ident_ids),
})
}
}
#[cfg(debug_assertions)]