correct misleading error for modules (#300)
This commit is contained in:
@@ -377,6 +377,19 @@ pub enum ModuleSource {
|
|||||||
File(ClauseName),
|
File(ClauseName),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ModuleSource {
|
||||||
|
pub fn as_functor_stub(&self) -> MachineStub {
|
||||||
|
match self {
|
||||||
|
ModuleSource::Library(ref name) => {
|
||||||
|
functor!("library", [clause_name(name.clone())])
|
||||||
|
}
|
||||||
|
ModuleSource::File(ref name) => {
|
||||||
|
functor!(clause_name(name.clone()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type ScopedPredicateKey = (ClauseName, PredicateKey); // module name, predicate indicator.
|
pub type ScopedPredicateKey = (ClauseName, PredicateKey); // module name, predicate indicator.
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|||||||
@@ -607,7 +607,13 @@ fn load_library(
|
|||||||
&listing_src,
|
&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))
|
Ok(wam_indices.insert_module(submodule))
|
||||||
} else {
|
} 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))
|
Ok(wam_indices.insert_module(submodule))
|
||||||
} else {
|
} 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);
|
insert_or_refresh_term_dir_quantum(term_dir, key, term_dirs);
|
||||||
}
|
}
|
||||||
None => {
|
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,
|
module: ClauseName,
|
||||||
indices: &mut IndexStore,
|
indices: &mut IndexStore,
|
||||||
) -> Result<(), SessionError> {
|
) -> 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 flags = wam.machine_flags();
|
||||||
let result = indices.use_module(&mut wam.code_repo, flags, &module);
|
let result = indices.use_module(&mut wam.code_repo, flags, &module);
|
||||||
|
|
||||||
wam.indices.insert_module(module);
|
wam.indices.insert_module(module);
|
||||||
result
|
result
|
||||||
} else {
|
} else {
|
||||||
Err(SessionError::ModuleNotFound)
|
let err = ExistenceError::SourceSink(ModuleSource::Library(
|
||||||
|
module
|
||||||
|
));
|
||||||
|
|
||||||
|
Err(SessionError::ExistenceError(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use prolog_parser::ast::*;
|
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::heap::*;
|
||||||
use crate::prolog::machine::machine_indices::*;
|
use crate::prolog::machine::machine_indices::*;
|
||||||
use crate::prolog::machine::machine_state::*;
|
use crate::prolog::machine::machine_state::*;
|
||||||
@@ -207,7 +207,7 @@ impl MachineError {
|
|||||||
ExistenceError::Module(name) => {
|
ExistenceError::Module(name) => {
|
||||||
let stub = functor!(
|
let stub = functor!(
|
||||||
"existence_error",
|
"existence_error",
|
||||||
[atom("module"), clause_name(name)]
|
[atom("source_sink"), clause_name(name)]
|
||||||
);
|
);
|
||||||
|
|
||||||
MachineError {
|
MachineError {
|
||||||
@@ -235,6 +235,21 @@ impl MachineError {
|
|||||||
from: ErrorProvenance::Constructed,
|
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) => {
|
ExistenceError::Stream(culprit) => {
|
||||||
let stub = functor!(
|
let stub = functor!(
|
||||||
"existence_error",
|
"existence_error",
|
||||||
@@ -301,8 +316,8 @@ impl MachineError {
|
|||||||
pub(super)
|
pub(super)
|
||||||
fn session_error(h: usize, err: SessionError) -> Self {
|
fn session_error(h: usize, err: SessionError) -> Self {
|
||||||
match err {
|
match err {
|
||||||
SessionError::CannotOverwriteBuiltIn(pred_str)
|
SessionError::CannotOverwriteBuiltIn(pred_str) |
|
||||||
| SessionError::CannotOverwriteImport(pred_str) => {
|
SessionError::CannotOverwriteImport(pred_str) => {
|
||||||
Self::permission_error(
|
Self::permission_error(
|
||||||
h,
|
h,
|
||||||
Permission::Modify,
|
Permission::Modify,
|
||||||
@@ -310,6 +325,9 @@ impl MachineError {
|
|||||||
functor!(clause_name(pred_str)),
|
functor!(clause_name(pred_str)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
SessionError::ExistenceError(err) => {
|
||||||
|
Self::existence_error(h, err)
|
||||||
|
}
|
||||||
SessionError::InvalidFileName(filename) => {
|
SessionError::InvalidFileName(filename) => {
|
||||||
Self::existence_error(h, ExistenceError::Module(filename))
|
Self::existence_error(h, ExistenceError::Module(filename))
|
||||||
}
|
}
|
||||||
@@ -321,14 +339,6 @@ impl MachineError {
|
|||||||
functor!("module_does_not_contain_claimed_export"),
|
functor!("module_does_not_contain_claimed_export"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
SessionError::ModuleNotFound => {
|
|
||||||
Self::permission_error(
|
|
||||||
h,
|
|
||||||
Permission::Access,
|
|
||||||
"private_procedure",
|
|
||||||
functor!("module_does_not_exist"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
SessionError::NamelessEntry => {
|
SessionError::NamelessEntry => {
|
||||||
Self::permission_error(
|
Self::permission_error(
|
||||||
h,
|
h,
|
||||||
@@ -685,15 +695,16 @@ impl MachineState {
|
|||||||
pub enum ExistenceError {
|
pub enum ExistenceError {
|
||||||
Module(ClauseName),
|
Module(ClauseName),
|
||||||
Procedure(ClauseName, usize),
|
Procedure(ClauseName, usize),
|
||||||
|
SourceSink(ModuleSource),
|
||||||
Stream(Addr),
|
Stream(Addr),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum SessionError {
|
pub enum SessionError {
|
||||||
CannotOverwriteBuiltIn(ClauseName),
|
CannotOverwriteBuiltIn(ClauseName),
|
||||||
CannotOverwriteImport(ClauseName),
|
CannotOverwriteImport(ClauseName),
|
||||||
|
ExistenceError(ExistenceError),
|
||||||
InvalidFileName(ClauseName),
|
InvalidFileName(ClauseName),
|
||||||
ModuleDoesNotContainExport(ClauseName, PredicateKey),
|
ModuleDoesNotContainExport(ClauseName, PredicateKey),
|
||||||
ModuleNotFound,
|
|
||||||
NamelessEntry,
|
NamelessEntry,
|
||||||
OpIsInfixAndPostFix(ClauseName),
|
OpIsInfixAndPostFix(ClauseName),
|
||||||
QueryCannotBePostedAsGoal,
|
QueryCannotBePostedAsGoal,
|
||||||
|
|||||||
@@ -288,7 +288,11 @@ impl Machine {
|
|||||||
|
|
||||||
Ok(self.indices.insert_module(module))
|
Ok(self.indices.insert_module(module))
|
||||||
} else {
|
} else {
|
||||||
Err(SessionError::ModuleNotFound)
|
let err = ExistenceError::SourceSink(ModuleSource::File(
|
||||||
|
clause_name!("$toplevel"),
|
||||||
|
));
|
||||||
|
|
||||||
|
Err(SessionError::ExistenceError(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -289,6 +289,9 @@ impl fmt::Display for IndexingInstruction {
|
|||||||
impl fmt::Display for SessionError {
|
impl fmt::Display for SessionError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
&SessionError::ExistenceError(ref err) => {
|
||||||
|
write!(f, "{}", err)
|
||||||
|
}
|
||||||
&SessionError::CannotOverwriteBuiltIn(ref msg) => {
|
&SessionError::CannotOverwriteBuiltIn(ref msg) => {
|
||||||
write!(f, "cannot overwrite {}", msg)
|
write!(f, "cannot overwrite {}", msg)
|
||||||
}
|
}
|
||||||
@@ -298,7 +301,6 @@ impl fmt::Display for SessionError {
|
|||||||
&SessionError::InvalidFileName(ref filename) => {
|
&SessionError::InvalidFileName(ref filename) => {
|
||||||
write!(f, "filename {} is invalid", filename)
|
write!(f, "filename {} is invalid", filename)
|
||||||
}
|
}
|
||||||
&SessionError::ModuleNotFound => write!(f, "module not found."),
|
|
||||||
&SessionError::ModuleDoesNotContainExport(ref module, ref key) => {
|
&SessionError::ModuleDoesNotContainExport(ref module, ref key) => {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
@@ -324,6 +326,38 @@ impl fmt::Display for SessionError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ExistenceError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
&ExistenceError::Module(ref module_name) => {
|
||||||
|
write!(f, "the module {} does not exist", module_name)
|
||||||
|
}
|
||||||
|
&ExistenceError::Procedure(ref name, arity) => {
|
||||||
|
write!(f, "the procedure {}/{} does not exist", name, arity)
|
||||||
|
}
|
||||||
|
&ExistenceError::SourceSink(ref module_source) => {
|
||||||
|
write!(f, "the source/sink {} does not exist", module_source)
|
||||||
|
}
|
||||||
|
&ExistenceError::Stream(ref addr) => {
|
||||||
|
write!(f, "the stream at {} does not exist", addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ModuleSource {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
&ModuleSource::File(ref file) => {
|
||||||
|
write!(f, "at the file {}", file)
|
||||||
|
}
|
||||||
|
&ModuleSource::Library(ref library) => {
|
||||||
|
write!(f, "at library({})", library)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for Line {
|
impl fmt::Display for Line {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
Reference in New Issue
Block a user