Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
src: Record and print global exception backtraces
We have a central place to catch global exceptions.  Unfortunately the
act of doing that hides the exception if OCAMLRUNPARAM=b was set.

We almost always want to see where these exceptions are thrown so turn
on exception recording unconditionally and print them.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=2124571
  • Loading branch information
rwmjones committed Sep 7, 2022
1 parent 5d3d21b commit ae7151c
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/supermin.ml
@@ -1,5 +1,5 @@
(* supermin 5
* Copyright (C) 2009-2014 Red Hat Inc.
* Copyright (C) 2009-2022 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -291,22 +291,32 @@ appliance automatically.
package_handler_shutdown ()

let () =
try main ()
try
Printexc.record_backtrace true;
main ()
with
| Unix.Unix_error (code, fname, "") -> (* from a syscall *)
error "error: %s: %s" fname (Unix.error_message code)
Printexc.print_backtrace Pervasives.stderr;
error "error: %s: %s" fname (Unix.error_message code)
| Unix.Unix_error (code, fname, param) -> (* from a syscall *)
error "error: %s: %s: %s" fname (Unix.error_message code) param
Printexc.print_backtrace Pervasives.stderr;
error "error: %s: %s: %s" fname (Unix.error_message code) param
| Failure msg -> (* from failwith/failwithf *)
error "failure: %s" msg
Printexc.print_backtrace Pervasives.stderr;
error "failure: %s" msg
| Librpm.Multiple_matches (package, count) -> (* from librpm *)
error "RPM error: %d occurrences for %s" count package
Printexc.print_backtrace Pervasives.stderr;
error "RPM error: %d occurrences for %s" count package
| Invalid_argument msg -> (* probably should never happen *)
error "internal error: invalid argument: %s" msg
Printexc.print_backtrace Pervasives.stderr;
error "internal error: invalid argument: %s" msg
| Assert_failure (file, line, char) -> (* should never happen *)
error "internal error: assertion failed at %s, line %d, char %d"
file line char
Printexc.print_backtrace Pervasives.stderr;
error "internal error: assertion failed at %s, line %d, char %d"
file line char
| Not_found -> (* should never happen *)
error "internal error: Not_found exception was thrown"
Printexc.print_backtrace Pervasives.stderr;
error "internal error: Not_found exception was thrown"
| exn -> (* something not matched above *)
error "exception: %s" (Printexc.to_string exn)
Printexc.print_backtrace Pervasives.stderr;
error "exception: %s" (Printexc.to_string exn)

0 comments on commit ae7151c

Please sign in to comment.