(
output: &mut W,
filename: &str,
lineno: usize,
)
| 367 | } |
| 368 | |
| 369 | fn print_source_line<W: Write>( |
| 370 | output: &mut W, |
| 371 | filename: &str, |
| 372 | lineno: usize, |
| 373 | ) -> Result<(), W::Error> { |
| 374 | // TODO: use io.open() method instead, when available, according to https://github.com/python/cpython/blob/main/Python/traceback.c#L393 |
| 375 | // TODO: support different encodings |
| 376 | let file = match std::fs::File::open(filename) { |
| 377 | Ok(file) => file, |
| 378 | Err(_) => return Ok(()), |
| 379 | }; |
| 380 | let file = BufReader::new(file); |
| 381 | |
| 382 | for (i, line) in file.lines().enumerate() { |
| 383 | if i + 1 == lineno { |
| 384 | if let Ok(line) = line { |
| 385 | // Indented with 4 spaces |
| 386 | writeln!(output, " {}", line.trim_start())?; |
| 387 | } |
| 388 | return Ok(()); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | Ok(()) |
| 393 | } |
| 394 | |
| 395 | /// Print exception occurrence location from traceback element |
| 396 | fn write_traceback_entry<W: Write>( |
no test coverage detected