Installs pre-commit hooks for OCaml projects that run dune fmt automatically

fix(lint): use Fmt.failwith and err_* helpers (E215/E340)

Replace failwith (Fmt.str ...) with Fmt.failwith, and introduce err_*
helper functions for Error (Fmt.str ...) patterns across pid1, precommit,
qemu (qmp_protocol, vm), and requests (tls_config, websocket).

+17 -11
+1 -1
bin/main.ml
··· 235 235 let width = int_of_string (String.trim (input_line ic)) in 236 236 ignore (Unix.close_process_in ic); 237 237 width 238 - with _ -> 80 238 + with Failure _ | End_of_file | Unix.Unix_error _ -> 80 239 239 240 240 let truncate_subject max_len s = 241 241 if String.length s <= max_len then s else String.sub s 0 (max_len - 1) ^ "…"
+16 -10
lib/precommit.ml
··· 6 6 7 7 module Log = (val Logs.src_log log_src : Logs.LOG) 8 8 9 + let err_no_dune_project dir = 10 + Error (Fmt.str "%s: No dune-project found (use --force to override)" dir) 11 + 12 + let err_no_git_dir dir = Error (Fmt.str "%s: No .git directory found" dir) 13 + 9 14 type ctx = { cwd : Eio.Fs.dir_ty Eio.Path.t; fs : Eio.Fs.dir_ty Eio.Path.t } 10 15 11 16 let ctx ~cwd ~fs = ··· 89 94 let read_file ~fs path = Eio.Path.load Eio.Path.(fs / path) 90 95 91 96 let write_file ~fs ~dry_run path content = 92 - if dry_run then Printf.printf "Would create %s\n" path 97 + if dry_run then Fmt.pr "Would create %s@." path 93 98 else Eio.Path.save ~create:(`Or_truncate 0o644) Eio.Path.(fs / path) content 94 99 95 100 let chmod_exec ~dry_run path = 96 - if dry_run then Printf.printf "Would chmod +x %s\n" path 97 - else Unix.chmod path 0o755 101 + if dry_run then Fmt.pr "Would chmod +x %s@." path else Unix.chmod path 0o755 98 102 99 103 let mkdir_p ~fs ~dry_run path = 100 - if dry_run then Printf.printf "Would create %s/\n" path 104 + if dry_run then Fmt.pr "Would create %s/@." path 101 105 else Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 Eio.Path.(fs / path) 102 106 103 107 let check_formatting_disabled ~fs path = ··· 153 157 let dune_project = Filename.concat dir "dune-project" in 154 158 let ocamlformat_path = Filename.concat dir ".ocamlformat" in 155 159 if (not force) && not (file_exists ~fs:ctx.cwd dune_project) then 156 - Error (Fmt.str "%s: No dune-project found (use --force to override)" dir) 160 + err_no_dune_project dir 157 161 else 158 162 match git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with 159 - | None -> Error (Fmt.str "%s: No .git directory found" dir) 163 + | None -> err_no_git_dir dir 160 164 | Some git_root -> 161 165 let git_dir_path = Filename.concat git_root ".git" in 162 166 let git_dir = resolve_git_dir ~fs:ctx.fs git_dir_path in ··· 268 272 else abs_path 269 273 270 274 let rec git_projects ctx dir = 271 - let entries = try Eio.Path.read_dir Eio.Path.(ctx.cwd / dir) with _ -> [] in 275 + let entries = 276 + try Eio.Path.read_dir Eio.Path.(ctx.cwd / dir) with Eio.Io _ -> [] 277 + in 272 278 let child_path name = if dir = "." then name else Filename.concat dir name in 273 279 (* If dir has .git, include it *) 274 280 let self_has_git = List.mem ".git" entries in ··· 340 346 let content = Eio.Path.load Eio.Path.(fs / global_config_path) in 341 347 let config = Git.Config.of_string content in 342 348 (Git.Config.user config).email 343 - with _ -> None) 349 + with Eio.Io _ | Failure _ -> None) 344 350 345 351 (* Check if commit was made by the current user *) 346 352 let is_my_commit ~user_email commit = ··· 442 448 443 449 let backup_branch ctx dir = 444 450 match git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with 445 - | None -> failwith (Fmt.str "%s: No .git directory found" dir) 451 + | None -> Fmt.failwith "%s: No .git directory found" dir 446 452 | Some git_root -> 447 453 let repo = Git.Repository.open_repo ~fs:ctx.fs (Fpath.v git_root) in 448 454 let branch = ··· 465 471 466 472 let rewrite_ai_attribution ctx dir = 467 473 match git_root ~cwd:ctx.cwd ~fs:ctx.fs dir with 468 - | None -> Error (Fmt.str "%s: No .git directory found" dir) 474 + | None -> err_no_git_dir dir 469 475 | Some git_root -> ( 470 476 let repo = Git.Repository.open_repo ~fs:ctx.fs (Fpath.v git_root) in 471 477 let user_email = user_email ~fs:ctx.fs repo in