mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-02 21:44:34 +00:00
Handle import errors
This commit is contained in:
parent
9c967d32f6
commit
a5a0324883
2 changed files with 21 additions and 11 deletions
|
@ -1,7 +1,6 @@
|
|||
use std::option::Option;
|
||||
use std::path::PathBuf; // conflicting to Type::Option
|
||||
|
||||
use erg_common::color::{RED, RESET};
|
||||
use erg_common::config::{ErgConfig, Input};
|
||||
use erg_common::error::MultiErrorDisplay;
|
||||
use erg_common::traits::{Locational, Stream};
|
||||
|
@ -22,7 +21,7 @@ use crate::build_hir::HIRBuilder;
|
|||
use crate::context::{ClassDefType, Context, DefaultInfo, RegistrationMode, TraitInstance};
|
||||
use crate::error::readable_name;
|
||||
use crate::error::{TyCheckError, TyCheckResult};
|
||||
use crate::hir;
|
||||
use crate::hir::{self, Literal};
|
||||
use crate::mod_cache::SharedModuleCache;
|
||||
use crate::varinfo::{Mutability, ParamIdx, VarInfo, VarKind};
|
||||
use Mutability::*;
|
||||
|
@ -820,8 +819,9 @@ impl Context {
|
|||
current_input,
|
||||
var_name,
|
||||
__name__,
|
||||
lit,
|
||||
mod_cache,
|
||||
),
|
||||
)?,
|
||||
}
|
||||
} else {
|
||||
// maybe unreachable
|
||||
|
@ -857,8 +857,9 @@ impl Context {
|
|||
current_input: Input,
|
||||
var_name: &VarName,
|
||||
__name__: Str,
|
||||
name_lit: &Literal,
|
||||
mod_cache: &SharedModuleCache,
|
||||
) {
|
||||
) -> TyCheckResult<()> {
|
||||
let mut dir = if let Input::File(mut path) = current_input {
|
||||
path.pop();
|
||||
path
|
||||
|
@ -867,13 +868,17 @@ impl Context {
|
|||
};
|
||||
dir.push(format!("{__name__}.er"));
|
||||
// TODO: returns an error
|
||||
let path = dir.canonicalize().unwrap_or_else(|err| {
|
||||
eprintln!(
|
||||
"failed to open {RED}{}{RESET}: {err}",
|
||||
dir.to_string_lossy()
|
||||
);
|
||||
std::process::exit(err.raw_os_error().unwrap_or(1));
|
||||
});
|
||||
let path = match dir.canonicalize() {
|
||||
Ok(path) => path,
|
||||
Err(err) => {
|
||||
return Err(TyCheckError::file_error(
|
||||
line!() as usize,
|
||||
err.to_string(),
|
||||
name_lit.loc(),
|
||||
self.caused_by(),
|
||||
));
|
||||
}
|
||||
};
|
||||
let cfg = ErgConfig {
|
||||
input: Input::File(path),
|
||||
..ErgConfig::default()
|
||||
|
@ -888,6 +893,7 @@ impl Context {
|
|||
errs.fmt_all_stderr();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn _push_subtype_bound(&mut self, sub: Type, sup: Type) {
|
||||
|
|
|
@ -1292,6 +1292,10 @@ passed keyword args: {RED}{kw_args_len}{RESET}"
|
|||
caused_by,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn file_error(errno: usize, desc: String, loc: Location, caused_by: AtomicStr) -> Self {
|
||||
Self::new(ErrorCore::new(errno, IoError, loc, desc, None), caused_by)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue