1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495(* This file is free software, part of dolmen. See file "LICENSE" for more information *)(* Exit codes *)(* ************************************************************************* *)typet={code:int;(* codes are unique for each exit code *)descr:string;category:string;mutableabort:bool;}lethasht=t.codeletequaltt'=t.code=t'.codeletcomparett'=comparet.codet'.codeletdescrt=t.code,t.descrletcategoryt=t.category(* Exit with a code and code status *)(* ************************************************************************* *)letis_abortt=t.abortletabortt=t.abort<-trueleterrort=t.abort<-falseletexitt=ift.abortthenUnix.kill(Unix.getpid())Sys.sigabrt;exitt.code(* Manipulation *)(* ************************************************************************* *)letcounter=ref0leterrors=ref[](* The create function should only be used for error exit codes,
the ok exit code (i.e. [0]) is create manually and not included
in the errors list. *)letcreate~category~descr=incrcounter;letcode=!counterin(* cmdliner uses retcode 124 for cli errors *)assert(0<code&&code<124);lett={code;descr;category;abort=false;}inerrors:=t::!errors;t(* *)leterrors()=List.rev!errors(* Special values *)(* ************************************************************************* *)letok={code=0;descr="the success exit code";category="N/A";abort=false;}letbug={code=125;descr="on unexpected internal errors (bugs)";category="Internal";abort=false;}(* Predefined values *)(* ************************************************************************* *)letgeneric=create~category:"Generic"~descr:"on generic error"letlimit=create~category:"Limits"~descr:"upon reaching limits (time, memory, etc..)"letparsing=create~category:"Parsing"~descr:"on parsing errors"lettyping=create~category:"Typing"~descr:"on typing errors"