1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(* $Id: cerrors.ml 11309 2008-08-06 10:30:35Z herbelin $ *)
20
if loc = dummy_loc then
23
let loc = unloc loc in
24
(int (fst loc) ++ str"-" ++ int (snd loc))
26
let guill s = "\""^s^"\""
29
if !Flags.debug then (str"in " ++ str s ++ str":" ++ spc ()) else (mt ())
31
(* assumption : explain_sys_exn does NOT end with a 'FNL anymore! *)
33
let rec explain_exn_default_aux anomaly_string report_fn = function
35
hov 0 (anomaly_string () ++ str "uncaught Stream.Failure.")
37
hov 0 (str "Syntax error: " ++ str txt ++ str ".")
39
hov 0 (str "Syntax error: " ++ str txt ++ str ".")
41
hov 0 (anomaly_string () ++ str "uncaught exception Sys_error " ++ str (guill msg) ++ report_fn ())
43
hov 0 (str "Error: " ++ where s ++ pps)
45
hov 0 (str "Out of memory.")
47
hov 0 (str "Stack overflow.")
49
hov 0 (anomaly_string () ++ where s ++ pps ++ report_fn ())
50
| Match_failure(filename,pos1,pos2) ->
51
hov 0 (anomaly_string () ++ str "Match failure in file " ++ str (guill filename) ++
52
if Sys.ocaml_version = "3.06" then
53
(str " from character " ++ int pos1 ++
54
str " to " ++ int pos2)
56
(str " at line " ++ int pos1 ++
57
str " character " ++ int pos2)
60
hov 0 (anomaly_string () ++ str "uncaught exception Not_found" ++ report_fn ())
62
hov 0 (anomaly_string () ++ str "uncaught exception Failure " ++ str (guill s) ++ report_fn ())
63
| Invalid_argument s ->
64
hov 0 (anomaly_string () ++ str "uncaught exception Invalid_argument " ++ str (guill s) ++ report_fn ())
66
hov 0 (fnl () ++ str "User interrupt.")
67
| Univ.UniverseInconsistency (o,u,v) ->
69
if !Constrextern.print_universes then
70
spc() ++ str "(cannot enforce" ++ spc() ++ Univ.pr_uni u ++ spc() ++
71
str (match o with Univ.Lt -> "<" | Univ.Le -> "<=" | Univ.Eq -> "=")
72
++ spc() ++ Univ.pr_uni v ++ str")"
75
hov 0 (str "Error: Universe inconsistency" ++ msg ++ str ".")
76
| TypeError(ctx,te) ->
77
hov 0 (str "Error:" ++ spc () ++ Himsg.explain_type_error ctx te)
78
| PretypeError(ctx,te) ->
79
hov 0 (str "Error:" ++ spc () ++ Himsg.explain_pretype_error ctx te)
80
| Typeclasses_errors.TypeClassError(env, te) ->
81
hov 0 (str "Error:" ++ spc () ++ Himsg.explain_typeclass_error env te)
83
hov 0 (str "Error:" ++ spc () ++ Himsg.explain_inductive_error e)
84
| RecursionSchemeError e ->
85
hov 0 (str "Error:" ++ spc () ++ Himsg.explain_recursion_scheme_error e)
86
| Proof_type.LtacLocated (_,(Refiner.FailError (i,s) as exc)) when s <> mt () ->
87
explain_exn_default_aux anomaly_string report_fn exc
88
| Proof_type.LtacLocated (s,exc) ->
89
hov 0 (Himsg.explain_ltac_call_trace s ++ fnl ()
90
++ explain_exn_default_aux anomaly_string report_fn exc)
91
| Cases.PatternMatchingError (env,e) ->
93
(str "Error:" ++ spc () ++ Himsg.explain_pattern_matching_error env e)
94
| Tacred.ReductionTacticError e ->
95
hov 0 (str "Error:" ++ spc () ++ Himsg.explain_reduction_tactic_error e)
96
| Logic.RefinerError e ->
97
hov 0 (str "Error:" ++ spc () ++ Himsg.explain_refiner_error e)
98
| Nametab.GlobalizationError q ->
99
hov 0 (str "Error:" ++ spc () ++
100
str "The reference" ++ spc () ++ Libnames.pr_qualid q ++
101
spc () ++ str "was not found" ++
102
spc () ++ str "in the current" ++ spc () ++ str "environment.")
103
| Nametab.GlobalizationConstantError q ->
104
hov 0 (str "Error:" ++ spc () ++
105
str "No constant of this name:" ++ spc () ++
106
Libnames.pr_qualid q ++ str ".")
107
| Refiner.FailError (i,s) ->
108
hov 0 (str "Error: Tactic failure" ++
109
(if s <> mt() then str ":" ++ s else mt ()) ++
110
if i=0 then str "." else str " (level " ++ int i ++ str").")
111
| Stdpp.Exc_located (loc,exc) ->
112
hov 0 ((if loc = dummy_loc then (mt ())
113
else (str"At location " ++ print_loc loc ++ str":" ++ fnl ()))
114
++ explain_exn_default_aux anomaly_string report_fn exc)
115
| Lexer.Error Illegal_character ->
116
hov 0 (str "Syntax error: Illegal character.")
117
| Lexer.Error Unterminated_comment ->
118
hov 0 (str "Syntax error: Unterminated comment.")
119
| Lexer.Error Unterminated_string ->
120
hov 0 (str "Syntax error: Unterminated string.")
121
| Lexer.Error Undefined_token ->
122
hov 0 (str "Syntax error: Undefined token.")
123
| Lexer.Error (Bad_token s) ->
124
hov 0 (str "Syntax error: Bad token" ++ spc () ++ str s ++ str ".")
125
| Assert_failure (s,b,e) ->
126
hov 0 (anomaly_string () ++ str "assert failure" ++ spc () ++
128
if Sys.ocaml_version = "3.06" then
129
(str ("(file \"" ^ s ^ "\", characters ") ++
130
int b ++ str "-" ++ int e ++ str ")")
132
(str ("(file \"" ^ s ^ "\", line ") ++ int b ++
133
str ", characters " ++ int e ++ str "-" ++
134
int (e+6) ++ str ")")
139
hov 0 (anomaly_string () ++ str "Uncaught exception " ++
140
str (Printexc.to_string reraise) ++ report_fn ())
142
let anomaly_string () = str "Anomaly: "
144
let report () = (str "." ++ spc () ++ str "Please report.")
146
let explain_exn_default =
147
explain_exn_default_aux anomaly_string report
149
let raise_if_debug e =
150
if !Flags.debug then raise e
152
let _ = Tactic_debug.explain_logic_error := explain_exn_default
154
let _ = Tactic_debug.explain_logic_error_no_anomaly :=
155
explain_exn_default_aux (fun () -> mt()) (fun () -> str ".")
157
let explain_exn_function = ref explain_exn_default
159
let explain_exn e = !explain_exn_function e