File: invariant.ml

package info (click to toggle)
janest-base 0.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,896 kB
  • sloc: ml: 37,596; ansic: 251; javascript: 114; makefile: 21
file content (25 lines) | stat: -rw-r--r-- 542 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
open! Import
include Invariant_intf

let raise_s = Error.raise_s

let invariant here t sexp_of_t f : unit =
  try f () with
  | exn ->
    raise_s
      (Sexp.message
         "invariant failed"
         [ "", Source_code_position0.sexp_of_t here
         ; "exn", sexp_of_exn exn
         ; "", sexp_of_t t
         ])
;;

let check_field t f field =
  try f (Field.get field t) with
  | exn ->
    raise_s
      (Sexp.message
         "problem with field"
         [ "field", sexp_of_string (Field.name field); "exn", sexp_of_exn exn ])
;;