throw exception when attempting to post query as goal (#329)
This commit is contained in:
@@ -301,9 +301,6 @@ 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::ParserError(err) => {
|
|
||||||
Self::syntax_error(h, err)
|
|
||||||
}
|
|
||||||
SessionError::CannotOverwriteBuiltIn(pred_str)
|
SessionError::CannotOverwriteBuiltIn(pred_str)
|
||||||
| SessionError::CannotOverwriteImport(pred_str) => {
|
| SessionError::CannotOverwriteImport(pred_str) => {
|
||||||
Self::permission_error(
|
Self::permission_error(
|
||||||
@@ -329,7 +326,15 @@ impl MachineError {
|
|||||||
h,
|
h,
|
||||||
Permission::Access,
|
Permission::Access,
|
||||||
"private_procedure",
|
"private_procedure",
|
||||||
functor!("modules_does_not_exist"),
|
functor!("module_does_not_exist"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
SessionError::NamelessEntry => {
|
||||||
|
Self::permission_error(
|
||||||
|
h,
|
||||||
|
Permission::Create,
|
||||||
|
"static_procedure",
|
||||||
|
functor!("nameless_procedure")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
SessionError::OpIsInfixAndPostFix(op) => {
|
SessionError::OpIsInfixAndPostFix(op) => {
|
||||||
@@ -340,7 +345,17 @@ impl MachineError {
|
|||||||
functor!(clause_name(op)),
|
functor!(clause_name(op)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
SessionError::ParserError(err) => {
|
||||||
|
Self::syntax_error(h, err)
|
||||||
|
}
|
||||||
|
SessionError::QueryCannotBePostedAsGoal => {
|
||||||
|
Self::permission_error(
|
||||||
|
h,
|
||||||
|
Permission::Create,
|
||||||
|
"static_procedure",
|
||||||
|
functor!("query_cannot_be_posted_as_goal")
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,6 +696,7 @@ pub enum SessionError {
|
|||||||
ModuleNotFound,
|
ModuleNotFound,
|
||||||
NamelessEntry,
|
NamelessEntry,
|
||||||
OpIsInfixAndPostFix(ClauseName),
|
OpIsInfixAndPostFix(ClauseName),
|
||||||
|
QueryCannotBePostedAsGoal,
|
||||||
ParserError(ParserError),
|
ParserError(ParserError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1290,7 +1290,7 @@ impl<'a> TopLevelBatchWorker<'a> {
|
|||||||
TopLevel::Declaration(decl) =>
|
TopLevel::Declaration(decl) =>
|
||||||
return Ok(Some(decl)),
|
return Ok(Some(decl)),
|
||||||
TopLevel::Query(_) =>
|
TopLevel::Query(_) =>
|
||||||
return Err(SessionError::NamelessEntry),
|
return Err(SessionError::QueryCannotBePostedAsGoal),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -289,7 +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::CannotOverwriteBuiltIn(ref msg) => write!(f, "cannot overwrite {}", msg),
|
&SessionError::CannotOverwriteBuiltIn(ref msg) => {
|
||||||
|
write!(f, "cannot overwrite {}", msg)
|
||||||
|
}
|
||||||
&SessionError::CannotOverwriteImport(ref msg) => {
|
&SessionError::CannotOverwriteImport(ref msg) => {
|
||||||
write!(f, "cannot overwrite import {}", msg)
|
write!(f, "cannot overwrite import {}", msg)
|
||||||
}
|
}
|
||||||
@@ -312,7 +314,12 @@ impl fmt::Display for SessionError {
|
|||||||
&SessionError::NamelessEntry => {
|
&SessionError::NamelessEntry => {
|
||||||
write!(f, "the predicate head is not an atom or clause.")
|
write!(f, "the predicate head is not an atom or clause.")
|
||||||
}
|
}
|
||||||
&SessionError::ParserError(ref e) => write!(f, "syntax_error({})", e.as_str()),
|
&SessionError::ParserError(ref e) => {
|
||||||
|
write!(f, "syntax_error({})", e.as_str())
|
||||||
|
}
|
||||||
|
&SessionError::QueryCannotBePostedAsGoal => {
|
||||||
|
write!(f, "query forms cannot be posted as goals.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user