123456789101112131415161718192021222324252627282930313233343536(*
Error management and exception printing
*)openPrintftypemsg=Errorofstring|WarningofstringexceptionTest_failureofstringexceptionUser_errorofstringexceptionInternal_errorof{loc:string;msg:string}letfail_testmsg=raise(Test_failuremsg)letuser_errormsg=raise(User_errormsg)letinternal_error~__LOC__:locmsg=raise(Internal_error{loc;msg})letassert_false~__LOC__:loc()=internal_error~__LOC__:loc"this shouldn't have happened"letinvalid_arg~__LOC__:locmsg=raise(Internal_error{loc;msg="Invalid argument: "^msg})let()=Printexc.register_printer(function|Test_failuremsg->Some(sprintf"Test failed: %s"msg)|User_errormsg->Some(sprintf"Error: %s"msg)|Internal_error{loc;msg}->Some(sprintf"Internal error in the Testo library at %s: %s"locmsg)|_->None)moduleExit_code=structletsuccess=0lettest_failure=1letconfiguration_error=2letinternal_error=3end