mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 04:50:36 +00:00
More output formatting improvements
This commit is contained in:
parent
7814282d3d
commit
3689eb17d2
5 changed files with 47 additions and 9 deletions
|
@ -14,9 +14,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- Improved general formatting of errors to make them more readable & glanceable
|
||||
- Improved output formatting of non-primitive types
|
||||
- Improved output formatting of empty tables
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed double stack trace for certain kinds of errors
|
||||
|
||||
## `0.0.4` - January 21st, 2023
|
||||
|
||||
### Added
|
||||
|
|
|
@ -96,7 +96,10 @@ impl Cli {
|
|||
// Display the file path relative to cwd with no extensions in stack traces
|
||||
let file_display_name = file_path.with_extension("").display().to_string();
|
||||
// Create a new lune object with all globals & run the script
|
||||
run_lune(&file_display_name, &file_contents, self.script_args).await?;
|
||||
if let Err(e) = run_lune(&file_display_name, &file_contents, self.script_args).await {
|
||||
eprintln!("{e}");
|
||||
std::process::exit(1);
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use crate::utils::table_builder::ReadonlyTableBuilder;
|
|||
|
||||
const DEFAULT_SLEEP_DURATION: f32 = 1.0 / 60.0;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct WaitingThread<'a> {
|
||||
is_delayed_for: Option<f32>,
|
||||
is_deferred: Option<bool>,
|
||||
|
@ -17,7 +18,7 @@ pub struct WaitingThread<'a> {
|
|||
args: Variadic<Value<'a>>,
|
||||
}
|
||||
|
||||
pub fn new<'a>(lua: &'a Lua, threads: &Arc<Mutex<Vec<WaitingThread<'a>>>>) -> Result<Table<'a>> {
|
||||
pub fn new<'a>(lua: &'a Lua, _threads: &Arc<Mutex<Vec<WaitingThread<'a>>>>) -> Result<Table<'a>> {
|
||||
// TODO: Figure out how to insert into threads vec
|
||||
ReadonlyTableBuilder::new(lua)?
|
||||
.with_async_function(
|
||||
|
|
|
@ -57,7 +57,7 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
if let Err(e) = run_lune($value, &script, args).await {
|
||||
panic!("Test '{}' failed!\n{}", $value, e.to_string())
|
||||
panic!("\nTest '{}' failed!\n{}\n", $value, e.to_string())
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
|
|
@ -191,24 +191,34 @@ pub fn pretty_format_multi_value(multi: &MultiValue) -> mlua::Result<String> {
|
|||
}
|
||||
|
||||
pub fn pretty_format_luau_error(e: &mlua::Error) -> String {
|
||||
match e {
|
||||
let stack_begin = format!("[{}Stack Begin{}]", COLOR_BLUE, COLOR_RESET);
|
||||
let stack_end = format!("[{}Stack End{}]", COLOR_BLUE, COLOR_RESET);
|
||||
let err_string = match e {
|
||||
mlua::Error::RuntimeError(e) => {
|
||||
// Add "Stack Begin" instead of default stack traceback string
|
||||
let err_string = e.to_string();
|
||||
let mut err_lines = err_string.lines().collect::<Vec<_>>();
|
||||
let mut err_lines = err_string
|
||||
.lines()
|
||||
.map(|s| s.to_string())
|
||||
.collect::<Vec<String>>();
|
||||
for (index, line) in err_lines.clone().iter().enumerate().rev() {
|
||||
if *line == "stack traceback:" {
|
||||
err_lines[index] = "Stack Begin";
|
||||
err_lines[index] = stack_begin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
err_lines.push("Stack End");
|
||||
// Add "Stack End" to the very end of the stack trace for symmetry
|
||||
err_lines.push(stack_end);
|
||||
err_lines.join("\n")
|
||||
}
|
||||
mlua::Error::CallbackError { cause, traceback } => {
|
||||
// Same error formatting as above
|
||||
format!(
|
||||
"{}\nStack Begin{}Stack End",
|
||||
"{}\n{}{}{}",
|
||||
pretty_format_luau_error(cause.as_ref()),
|
||||
traceback.strip_prefix("stack traceback:\n").unwrap()
|
||||
stack_begin,
|
||||
traceback.strip_prefix("stack traceback:\n").unwrap(),
|
||||
stack_end
|
||||
)
|
||||
}
|
||||
mlua::Error::ToLuaConversionError { from, to, message } => {
|
||||
|
@ -230,5 +240,24 @@ pub fn pretty_format_luau_error(e: &mlua::Error) -> String {
|
|||
)
|
||||
}
|
||||
e => format!("{e}"),
|
||||
};
|
||||
let mut err_lines = err_string.lines().collect::<Vec<_>>();
|
||||
// Remove the script path from the error message
|
||||
// itself, it can be found in the stack trace
|
||||
if let Some(first_line) = err_lines.first() {
|
||||
if first_line.starts_with("[string \"") {
|
||||
if let Some(closing_bracket) = first_line.find("]:") {
|
||||
let after_closing_bracket = &first_line[closing_bracket + 2..first_line.len()];
|
||||
if let Some(last_colon) = after_closing_bracket.find(": ") {
|
||||
err_lines[0] = &after_closing_bracket
|
||||
[last_colon + 2..first_line.len() - closing_bracket - 2];
|
||||
} else {
|
||||
err_lines[0] = after_closing_bracket
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reformat stack trace lines, ignore lines that just mention C functions
|
||||
// Merge all lines back together into one string
|
||||
err_lines.join("\n")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue