Error Messaging Redesign
This commit contains the following: * New data types to support full tracebacks * New traceback data type used across stl and ast * Updates to tests * fixes for error messaging in sym and some stl functions
This commit is contained in:
parent
91ad4eed12
commit
789349df48
24 changed files with 837 additions and 374 deletions
27
src/run.rs
27
src/run.rs
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
use crate::eval::eval;
|
||||
use crate::lex::lex;
|
||||
use crate::error::{Traceback, start_trace};
|
||||
use crate::segment::{Ctr, Seg};
|
||||
use crate::sym::SymTable;
|
||||
use std::path::Path;
|
||||
|
|
@ -47,10 +48,12 @@ pub fn find_on_path(filename: String) -> Option<String> {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn run(filename: String, syms: &mut SymTable) -> Result<(), String> {
|
||||
pub fn run(filename: String, syms: &mut SymTable) -> Result<(), Traceback> {
|
||||
let script_read_res = fs::read_to_string(filename);
|
||||
if script_read_res.is_err() {
|
||||
Err(format!("Couldnt read script: {}", script_read_res.err().unwrap()))
|
||||
Err(start_trace(
|
||||
("<call script>", format!("Couldnt read script: {}", script_read_res.err().unwrap()))
|
||||
.into()))
|
||||
} else {
|
||||
let script_read = script_read_res.unwrap() + ")";
|
||||
let script = "(".to_string() + &script_read;
|
||||
|
|
@ -62,7 +65,7 @@ pub fn run(filename: String, syms: &mut SymTable) -> Result<(), String> {
|
|||
pub const RUN_DOCSTRING: &str = "Takes one string argument.
|
||||
Attempts to find argument in PATH and attempts to call argument";
|
||||
|
||||
pub fn run_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
||||
pub fn run_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, Traceback> {
|
||||
if let Ctr::String(ref filename) = *ast.car {
|
||||
if filename.ends_with(".rls") {
|
||||
if let Some(filepath) = find_on_path(filename.to_string()) {
|
||||
|
|
@ -71,10 +74,12 @@ pub fn run_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
|||
} else {
|
||||
let canonical_path_res = fs::canonicalize(filename);
|
||||
if canonical_path_res.is_err() {
|
||||
return Err(canonical_path_res
|
||||
.err()
|
||||
.unwrap()
|
||||
.to_string());
|
||||
return Err(start_trace(
|
||||
("<call script>", canonical_path_res
|
||||
.err()
|
||||
.unwrap()
|
||||
.to_string())
|
||||
.into()))
|
||||
}
|
||||
let canonical_path = canonical_path_res.ok().unwrap();
|
||||
return run(
|
||||
|
|
@ -85,9 +90,13 @@ pub fn run_callback(ast: &Seg, syms: &mut SymTable) -> Result<Ctr, String> {
|
|||
).and(Ok(Ctr::None))
|
||||
}
|
||||
} else {
|
||||
return Err("binary called, unimplemented!".to_string())
|
||||
return Err(start_trace(
|
||||
("<call script>", "binary called, unimplemented!")
|
||||
.into()))
|
||||
}
|
||||
} else {
|
||||
Err("impossible: not a string".to_string())
|
||||
Err(start_trace(
|
||||
("<call script>", "impossible: not a string")
|
||||
.into()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue