Add offer_suggestions on write_exception_inner

Signed-off-by: snowapril <sinjihng@gmail.com>
This commit is contained in:
snowapril
2021-10-10 23:49:47 +09:00
parent 6339390629
commit db0d9df53f

View File

@@ -7,6 +7,7 @@ use crate::{
function::{ArgIterable, FuncArgs, IntoPyException, IntoPyObject},
py_io::{self, Write},
stdlib::sys,
suggestion::offer_suggestions,
IdProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, StaticType,
TryFromObject, TypeProtocol, VirtualMachine,
};
@@ -129,17 +130,22 @@ impl VirtualMachine {
let varargs = exc.args();
let args_repr = vm.exception_args_as_string(varargs, true);
let exc_type = exc.class();
let exc_name = exc_type.name();
let exc_class = exc.class();
let exc_name = exc_class.name();
match args_repr.len() {
0 => writeln!(output, "{}", exc_name),
1 => writeln!(output, "{}: {}", exc_name, args_repr[0]),
_ => writeln!(
0 => write!(output, "{}", exc_name),
1 => write!(output, "{}: {}", exc_name, args_repr[0]),
_ => write!(
output,
"{}: ({})",
exc_name,
args_repr.into_iter().format(", ")
),
}?;
match offer_suggestions(exc, vm) {
Some(suggestions) => writeln!(output, ". Did you mean: '{}'?", suggestions.to_string()),
None => writeln!(output),
}
}