better logging, do not error on close

This commit is contained in:
Simon Cruanes 2024-02-18 23:44:10 -05:00
parent 20a36919ce
commit 0d1bccfd1b
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -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 _ _ ->