package octez-l2-libs

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file store_errors.ml

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2022-2023 Nomadic Labs, <contact@nomadic-labs.com>          *)
(* Copyright (c) 2023 Trili Tech, <contact@trili.tech>                       *)
(*                                                                           *)
(* Permission is hereby granted, free of charge, to any person obtaining a   *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense,  *)
(* and/or sell copies of the Software, and to permit persons to whom the     *)
(* Software is furnished to do so, subject to the following conditions:      *)
(*                                                                           *)
(* The above copyright notice and this permission notice shall be included   *)
(* in all copies or substantial portions of the Software.                    *)
(*                                                                           *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER       *)
(* DEALINGS IN THE SOFTWARE.                                                 *)
(*                                                                           *)
(*****************************************************************************)

type error +=
  | Cannot_load_store of {name : string; path : string}
  | Cannot_write_to_store of string
  | Cannot_write_key_value_pair_to_store of {
      key : string;
      value : string;
      name : string;
    }
  | Cannot_write_singleton_value_to_store of {value : string; name : string}
  | Cannot_remove_key_from_store of {key : string; name : string}
  | Cannot_read_from_store of string
  | Cannot_read_key_from_store of {key : string; name : string}
  | Decoding_error of Data_encoding.Binary.read_error
  | Encoding_error of Data_encoding.Binary.write_error
  | Cannot_close_store of string
  | Cannot_overwrite_key_in_store of {
      key : string;
      old_value : string;
      new_value : string;
      name : string;
    }
  | Gc_failed of string

let pp_hex ppf s = Hex.pp ppf (Hex.of_string s)

let () =
  register_error_kind
    ~id:"layer2_store.cannot_load_store"
    ~title:"Store cannot be loaded"
    ~description:"Store cannot be loaded."
    ~pp:(fun ppf (name, path) ->
      Format.fprintf ppf "Store %s cannot be loaded from %s." name path)
    `Permanent
    Data_encoding.(obj2 (req "name" string) (req "path" string))
    (function Cannot_load_store {name; path} -> Some (name, path) | _ -> None)
    (fun (name, path) -> Cannot_load_store {name; path})

let () =
  register_error_kind
    ~id:"layer2_store.cannot_write_to_store"
    ~title:"Cannot write to store"
    ~description:"Cannot write to store %s."
    ~pp:(fun ppf name -> Format.fprintf ppf "Cannot write to store %s." name)
    `Permanent
    Data_encoding.(obj1 (req "name" string))
    (function Cannot_write_to_store name -> Some name | _ -> None)
    (fun n -> Cannot_write_to_store n)

let () =
  register_error_kind
    ~id:"layer2_store.cannot_write_key_value_pair_to_store"
    ~title:"Cannot write key-value pair to store"
    ~description:"Cannot write key-value pair to store."
    ~pp:(fun ppf (key, value, name) ->
      Format.fprintf
        ppf
        "The key-value pair with key %a and value %a cannot be written to \
         store %s."
        pp_hex
        key
        pp_hex
        value
        name)
    `Permanent
    Data_encoding.(
      obj3
        (req "key" (string' Hex))
        (req "value" (string' Hex))
        (req "name" string))
    (function
      | Cannot_write_key_value_pair_to_store {key; value; name} ->
          Some (key, value, name)
      | _ -> None)
    (fun (key, value, name) ->
      Cannot_write_key_value_pair_to_store {key; value; name})

let () =
  register_error_kind
    ~id:"layer2_store.cannot_write_singleton_value_to_store"
    ~title:"Cannot write singleton value to store"
    ~description:"Cannot write singleton value to store."
    ~pp:(fun ppf (value, name) ->
      Format.fprintf
        ppf
        "The singleton value %a cannot be written to store %s."
        pp_hex
        value
        name)
    `Permanent
    Data_encoding.(obj2 (req "value" (string' Hex)) (req "name" string))
    (function
      | Cannot_write_singleton_value_to_store {value; name} -> Some (value, name)
      | _ -> None)
    (fun (value, name) -> Cannot_write_singleton_value_to_store {value; name})

let () =
  register_error_kind
    ~id:"layer2_store.cannot_remove_key_from_store"
    ~title:"Cannot remove key from store"
    ~description:"Cannot remove key from store."
    ~pp:(fun ppf (key, name) ->
      Format.fprintf ppf "Cannot remove key %a from store %s" pp_hex key name)
    `Permanent
    Data_encoding.(obj2 (req "key" (string' Hex)) (req "name" string))
    (function
      | Cannot_remove_key_from_store {key; name} -> Some (key, name) | _ -> None)
    (fun (key, name) -> Cannot_remove_key_from_store {key; name})

let () =
  register_error_kind
    ~id:"layer2_store.cannot_close_store"
    ~title:"Store cannot be closed"
    ~description:"Store cannot be closed."
    ~pp:(fun ppf name -> Format.fprintf ppf "Store %s cannot be closed." name)
    `Permanent
    Data_encoding.(obj1 (req "name" string))
    (function Cannot_close_store n -> Some n | _ -> None)
    (fun n -> Cannot_close_store n)

let () =
  register_error_kind
    ~id:"layer2_store.cannot_read_from_store"
    ~title:"Value cannot be read from store"
    ~description:"Value cannot be read from store."
    ~pp:(fun ppf name ->
      Format.fprintf ppf "Value cannot be read from store %s." name)
    `Permanent
    Data_encoding.(obj1 (req "name" string))
    (function Cannot_read_from_store n -> Some n | _ -> None)
    (fun n -> Cannot_read_from_store n)

let () =
  register_error_kind
    ~id:"layer2_store.cannot_read_key_from_store"
    ~title:"Cannot read key from store"
    ~description:"Cannot read key from store."
    ~pp:(fun ppf (key, name) ->
      Format.fprintf ppf "Cannot read key %a from store %s" pp_hex key name)
    `Permanent
    Data_encoding.(obj2 (req "key" (string' Hex)) (req "name" string))
    (function
      | Cannot_read_key_from_store {key; name} -> Some (key, name) | _ -> None)
    (fun (key, name) -> Cannot_read_key_from_store {key; name})

let () =
  register_error_kind
    ~id:"layer2_store.decoding_error"
    ~title:"Cannot decode persisted element"
    ~description:"The raw value for a persisted element could not be decoded"
    ~pp:(fun ppf error ->
      Format.fprintf
        ppf
        "Decoding error: %a"
        Data_encoding.Json.pp
        (Data_encoding.Json.construct
           Data_encoding.Binary.read_error_encoding
           error))
    `Permanent
    Data_encoding.(obj1 (req "error" Data_encoding.Binary.read_error_encoding))
    (function Decoding_error e -> Some e | _ -> None)
    (fun e -> Decoding_error e)

let () =
  register_error_kind
    ~id:"layer2_store.encoding_error"
    ~title:"Cannot encode element"
    ~description:"An element could not be encoded to a raw value."
    ~pp:(fun ppf error ->
      Format.fprintf
        ppf
        "Encoding error: %a"
        Data_encoding.Json.pp
        (Data_encoding.Json.construct
           Data_encoding.Binary.write_error_encoding
           error))
    `Permanent
    Data_encoding.(obj1 (req "error" Data_encoding.Binary.write_error_encoding))
    (function Encoding_error e -> Some e | _ -> None)
    (fun e -> Encoding_error e)

let () =
  register_error_kind
    ~id:"layer2_store.cannot_overwrite_key_in_store"
    ~title:"Key is already present with a different value in store"
    ~description:"Key is already present with a different value in store."
    ~pp:(fun ppf (key, old_value, new_value, name) ->
      Format.fprintf
        ppf
        "Cannot update key %a to value %a in store %s, as a binding for the \
         key with a different value %a already exists."
        pp_hex
        key
        pp_hex
        new_value
        name
        pp_hex
        old_value)
    `Permanent
    Data_encoding.(
      obj4
        (req "key" (string' Hex))
        (req "old_value" (string' Hex))
        (req "new_value" (string' Hex))
        (req "name" string))
    (function
      | Cannot_overwrite_key_in_store {key; old_value; new_value; name} ->
          Some (key, old_value, new_value, name)
      | _ -> None)
    (fun (key, old_value, new_value, name) ->
      Cannot_overwrite_key_in_store {key; old_value; new_value; name})

let () =
  register_error_kind
    ~id:"layer2_store.gc_failed"
    ~title:"GC of store failed"
    ~description:"Garbage collection of store failed."
    ~pp:(fun ppf name ->
      Format.fprintf ppf "Garbage collection of store %s failed." name)
    `Permanent
    Data_encoding.(obj1 (req "name" string))
    (function Gc_failed n -> Some n | _ -> None)
    (fun n -> Gc_failed n)
OCaml

Innovation. Community. Security.