From 0d1bccfd1b85097bb09a70f4013f16823d0c57f0 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sun, 18 Feb 2024 23:44:10 -0500 Subject: [PATCH] better logging, do not error on close --- src/Tiny_httpd_dir.ml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Tiny_httpd_dir.ml b/src/Tiny_httpd_dir.ml index b3fb6fb7..ad048449 100644 --- a/src/Tiny_httpd_dir.ml +++ b/src/Tiny_httpd_dir.ml @@ -95,7 +95,7 @@ let vfs_of_dir (top : string) : vfs = let read_file_content f = let ic = Unix.(openfile (top // f) [ O_RDONLY ] 0) in - Tiny_httpd_stream.of_fd ic + Tiny_httpd_stream.of_fd_close_noerr ic let create f = let oc = open_out_bin (top // f) in @@ -330,8 +330,12 @@ let add_vfs_ ~on_fs ~top ~config ~vfs:((module VFS : VFS) as vfs) ~prefix server ~headers:(mime_type @ [ "Etag", Lazy.force mtime ]) ~code:200 stream with e -> - S.Response.fail ~code:500 "error while reading file: %s" - (Printexc.to_string e) + let bt = Printexc.get_raw_backtrace () in + let msg = Printexc.to_string e in + Log.error (fun k -> + k "dir.get failed: %s@.%s" msg + (Printexc.raw_backtrace_to_string bt)); + S.Response.fail ~code:500 "error while reading file: %s" msg )) else S.add_route_handler server ~meth:`GET (route ()) (fun _ _ ->