/
exception.opa
89 lines (79 loc) · 2.74 KB
/
exception.opa
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Common Opa Exceptions
*
* @destination public
* @stabilization work in progress
**/
/**
* {1 About this module}
*
* Opa exception are used internally by generated code to report error,
* but it is discouraged to use them in a standard code.
*
* A next version of Opa will have a support for typing and extending exceptions.
* Currently, exceptions are available only on server side, and are all unified
* as there were inhabitant of the same sum type, as long as the compiler find
* occurrences of @catch and @throw in the code.
*
* This module contains the definition of the most common exceptions.
*
* Raised on the server side, this will either executed the handler code if there
* is any, or print an uncaught Opa exception message error.
*
* Raised on the client side, this will end up with an uncaught Javascript OpaException error.
* For rpc the client Opa exception should contain a JSon representation of the corresponding
* Opa exception.
*
* The syntax is the same as a [match with], with the [try catch] keywords instead.
*
* {[
* try
* expr
* catch
* | { e } ->
* }
*
* {1 Where should I start?}
*
* {1 What if I need more?}
**/
/**
* <!> Built in [BslNativeLib.ml]
**/
@opacapi
type Exception.common =
{ fail : string ; position : string }
/**
* Raised on the server side when it executes a [@fail] directive
**/
/ { Transaction_failure }
/**
* Internal error of the database. Not meant to be caught by an user.
**/
/ { ocaml_exc : string ; bslkey : string }
/**
* An ocaml exception raised by a server bypass.
* If the bypass is tagged as [raise], the exception is serialized
* using [Printexc.to_string], and the [bslkey] of the bypass is
* stored in the Opa exception.
**/
// This is a hack for preserving the type of exceptions
@private @server_private _dead_code() =
match 0 with
| 1 -> @throw( @opensums( { fail = "" ; position = "" } : Exception.common ) )
| 2 -> @throw( @opensums( { Transaction_failure } : Exception.common ) )
| 3 -> @throw( @opensums( { ocaml_exc = "" ; bslkey = "" } : Exception.common ) )
| _ -> void