correct misleading error for modules (#300)
This commit is contained in:
@@ -607,7 +607,13 @@ fn load_library(
|
||||
&listing_src,
|
||||
)
|
||||
}
|
||||
None => Err(SessionError::ModuleNotFound)
|
||||
None => {
|
||||
let err = ExistenceError::SourceSink(ModuleSource::Library(
|
||||
name.clone()
|
||||
));
|
||||
|
||||
Err(SessionError::ExistenceError(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,7 +699,11 @@ impl ListingCompiler {
|
||||
|
||||
Ok(wam_indices.insert_module(submodule))
|
||||
} else {
|
||||
Err(SessionError::ModuleNotFound)
|
||||
let err = ExistenceError::SourceSink(ModuleSource::File(
|
||||
module_name,
|
||||
));
|
||||
|
||||
Err(SessionError::ExistenceError(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -727,7 +737,11 @@ impl ListingCompiler {
|
||||
|
||||
Ok(wam_indices.insert_module(submodule))
|
||||
} else {
|
||||
Err(SessionError::ModuleNotFound)
|
||||
let err = ExistenceError::SourceSink(ModuleSource::File(
|
||||
module_name
|
||||
));
|
||||
|
||||
Err(SessionError::ExistenceError(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1057,7 +1071,11 @@ impl ListingCompiler {
|
||||
insert_or_refresh_term_dir_quantum(term_dir, key, term_dirs);
|
||||
}
|
||||
None => {
|
||||
return Err(SessionError::ModuleNotFound);
|
||||
let err = ExistenceError::SourceSink(ModuleSource::File(
|
||||
module_name,
|
||||
));
|
||||
|
||||
return Err(SessionError::ExistenceError(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1392,14 +1410,18 @@ pub(super) fn setup_indices(
|
||||
module: ClauseName,
|
||||
indices: &mut IndexStore,
|
||||
) -> Result<(), SessionError> {
|
||||
if let Some(module) = wam.indices.take_module(module) {
|
||||
if let Some(module) = wam.indices.take_module(module.clone()) {
|
||||
let flags = wam.machine_flags();
|
||||
let result = indices.use_module(&mut wam.code_repo, flags, &module);
|
||||
|
||||
wam.indices.insert_module(module);
|
||||
result
|
||||
} else {
|
||||
Err(SessionError::ModuleNotFound)
|
||||
let err = ExistenceError::SourceSink(ModuleSource::Library(
|
||||
module
|
||||
));
|
||||
|
||||
Err(SessionError::ExistenceError(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use prolog_parser::ast::*;
|
||||
|
||||
use crate::prolog::forms::{Number, PredicateKey};
|
||||
use crate::prolog::forms::{ModuleSource, Number, PredicateKey};
|
||||
use crate::prolog::machine::heap::*;
|
||||
use crate::prolog::machine::machine_indices::*;
|
||||
use crate::prolog::machine::machine_state::*;
|
||||
@@ -207,7 +207,7 @@ impl MachineError {
|
||||
ExistenceError::Module(name) => {
|
||||
let stub = functor!(
|
||||
"existence_error",
|
||||
[atom("module"), clause_name(name)]
|
||||
[atom("source_sink"), clause_name(name)]
|
||||
);
|
||||
|
||||
MachineError {
|
||||
@@ -235,6 +235,21 @@ impl MachineError {
|
||||
from: ErrorProvenance::Constructed,
|
||||
}
|
||||
}
|
||||
ExistenceError::SourceSink(source) => {
|
||||
let source_stub = source.as_functor_stub();
|
||||
|
||||
let stub = functor!(
|
||||
"existence_error",
|
||||
[atom("source_sink"), aux(h, 0)],
|
||||
[source_stub]
|
||||
);
|
||||
|
||||
MachineError {
|
||||
stub,
|
||||
location: None,
|
||||
from: ErrorProvenance::Constructed,
|
||||
}
|
||||
}
|
||||
ExistenceError::Stream(culprit) => {
|
||||
let stub = functor!(
|
||||
"existence_error",
|
||||
@@ -301,8 +316,8 @@ impl MachineError {
|
||||
pub(super)
|
||||
fn session_error(h: usize, err: SessionError) -> Self {
|
||||
match err {
|
||||
SessionError::CannotOverwriteBuiltIn(pred_str)
|
||||
| SessionError::CannotOverwriteImport(pred_str) => {
|
||||
SessionError::CannotOverwriteBuiltIn(pred_str) |
|
||||
SessionError::CannotOverwriteImport(pred_str) => {
|
||||
Self::permission_error(
|
||||
h,
|
||||
Permission::Modify,
|
||||
@@ -310,6 +325,9 @@ impl MachineError {
|
||||
functor!(clause_name(pred_str)),
|
||||
)
|
||||
}
|
||||
SessionError::ExistenceError(err) => {
|
||||
Self::existence_error(h, err)
|
||||
}
|
||||
SessionError::InvalidFileName(filename) => {
|
||||
Self::existence_error(h, ExistenceError::Module(filename))
|
||||
}
|
||||
@@ -321,14 +339,6 @@ impl MachineError {
|
||||
functor!("module_does_not_contain_claimed_export"),
|
||||
)
|
||||
}
|
||||
SessionError::ModuleNotFound => {
|
||||
Self::permission_error(
|
||||
h,
|
||||
Permission::Access,
|
||||
"private_procedure",
|
||||
functor!("module_does_not_exist"),
|
||||
)
|
||||
}
|
||||
SessionError::NamelessEntry => {
|
||||
Self::permission_error(
|
||||
h,
|
||||
@@ -685,15 +695,16 @@ impl MachineState {
|
||||
pub enum ExistenceError {
|
||||
Module(ClauseName),
|
||||
Procedure(ClauseName, usize),
|
||||
SourceSink(ModuleSource),
|
||||
Stream(Addr),
|
||||
}
|
||||
|
||||
pub enum SessionError {
|
||||
CannotOverwriteBuiltIn(ClauseName),
|
||||
CannotOverwriteImport(ClauseName),
|
||||
ExistenceError(ExistenceError),
|
||||
InvalidFileName(ClauseName),
|
||||
ModuleDoesNotContainExport(ClauseName, PredicateKey),
|
||||
ModuleNotFound,
|
||||
NamelessEntry,
|
||||
OpIsInfixAndPostFix(ClauseName),
|
||||
QueryCannotBePostedAsGoal,
|
||||
|
||||
@@ -288,7 +288,11 @@ impl Machine {
|
||||
|
||||
Ok(self.indices.insert_module(module))
|
||||
} else {
|
||||
Err(SessionError::ModuleNotFound)
|
||||
let err = ExistenceError::SourceSink(ModuleSource::File(
|
||||
clause_name!("$toplevel"),
|
||||
));
|
||||
|
||||
Err(SessionError::ExistenceError(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user