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:
Ava Apples Affine 2023-05-23 22:06:11 +00:00
parent 91ad4eed12
commit 789349df48
24 changed files with 837 additions and 374 deletions

View file

@ -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()))
}
}