MCPcopy Index your code
hub / github.com/RustPython/RustPython / write_exception_inner

Method write_exception_inner

crates/vm/src/exceptions.rs:132–170  ·  view source on GitHub ↗

Print exception with traceback

(
        &self,
        output: &mut W,
        exc: &Py<PyBaseException>,
    )

Source from the content-addressed store, hash-verified

130
131 /// Print exception with traceback
132 pub fn write_exception_inner<W: Write>(
133 &self,
134 output: &mut W,
135 exc: &Py<PyBaseException>,
136 ) -> Result<(), W::Error> {
137 let vm = self;
138 if let Some(tb) = exc.traceback.read().clone() {
139 writeln!(output, "Traceback (most recent call last):")?;
140 for tb in tb.iter() {
141 write_traceback_entry(output, &tb)?;
142 }
143 }
144
145 let varargs = exc.args();
146 let args_repr = vm.exception_args_as_string(varargs, true);
147
148 let exc_class = exc.class();
149
150 if exc_class.fast_issubclass(vm.ctx.exceptions.syntax_error) {
151 return self.write_syntaxerror(output, exc, exc_class, &args_repr);
152 }
153
154 let exc_name = exc_class.name();
155 match args_repr.len() {
156 0 => write!(output, "{exc_name}"),
157 1 => write!(output, "{}: {}", exc_name, args_repr[0]),
158 _ => write!(
159 output,
160 "{}: ({})",
161 exc_name,
162 args_repr.into_iter().format(", "),
163 ),
164 }?;
165
166 match offer_suggestions(exc, vm) {
167 Some(suggestions) => writeln!(output, ". Did you mean: '{suggestions}'?"),
168 None => writeln!(output),
169 }
170 }
171
172 /// Format and write a SyntaxError
173 /// This logic is derived from TracebackException._format_syntax_error

Callers 1

Calls 12

write_traceback_entryFunction · 0.85
offer_suggestionsFunction · 0.85
fast_issubclassMethod · 0.80
write_syntaxerrorMethod · 0.80
cloneMethod · 0.45
readMethod · 0.45
iterMethod · 0.45
argsMethod · 0.45
classMethod · 0.45
nameMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected