Right now we can see errors in the log but we don't have the line number or a backtrace.
Easier to track down a bug.
I believe this might be This is blocked on an http-types release, but then will absolutely be possible
Awesome. Thank you very much.
On a related note, when using anyhow, could we get the error and the cause in the logger?
In this example, the case with tide::log::middleware doesn't show No such file or directory (os error 2).
Should I open a new issue/feature request?
code
use anyhow::{Error, Context};
use tide::Request;
use std::fs::File;
#[async_std::main]
async fn main() -> tide::Result<()> {
if let Err(e) = example() {
println!("err: {:?}", e);
}
tide::log::with_level(tide::log::LevelFilter::Info);
let mut app = tide::new();
app.at("/").get(index);
app.with(tide::log::LogMiddleware::new());
app.listen("127.0.0.1:8080").await?;
Ok(())
}
fn example() -> Result<(), Error> {
let _file = File::open("non-existing-file1.txt")
.context("can't open non-existing-file1.txt")?;
unimplemented!();
}
async fn index(_req: Request<()>) -> tide::Result {
let _file = File::open("non-existing-file2.txt")
.context("can't open non-existing-file2.txt")?;
unimplemented!();
}
output
err: can't open non-existing-file1.txt
Caused by:
No such file or directory (os error 2)
tide::log::middleware <-- Request received
method GET
path /
tide::log::middleware Internal error --> Response sent
message can't open non-existing-file2.txt
method GET
path /
status 500
duration 79.312碌s
Fwiw I also came across this and I have a patch essentially ready from an internal logger.
Which case, the backtrace one or the anyhow one?
Backtrace, error type name. I think I have a hunch on how to get the description properly as well.
It seems to work perfectly. Thank you very much!
Most helpful comment
Fwiw I also came across this and I have a patch essentially ready from an internal logger.