package stog

  1. Overview
  2. Docs
Static web site compiler, able to handle blog posts as well as regular pages or any XML document in general

Install

dune-project
 Dependency

Authors

Maintainers

Sources

stog-1.0.0.tar.gz
md5=e9ce23a296e6309688a2d459fcbf9320
sha512=eeffb8957436879409d66138941770d5a7941cbb89d138f78b6ab35d4b8c198886e559ec4af026256b03da732f897306eda59fcd5b93ece5907a144321419d4e

doc/src/stog/error.ml.html

Source file error.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
(*********************************************************************************)
(*                Stog                                                           *)
(*                                                                               *)
(*    Copyright (C) 2012-2024 INRIA All rights reserved.                         *)
(*    Author: Maxence Guesdon, INRIA Saclay                                      *)
(*                                                                               *)
(*    This program is free software; you can redistribute it and/or modify       *)
(*    it under the terms of the GNU General Public License as                    *)
(*    published by the Free Software Foundation, version 3 of the License.       *)
(*                                                                               *)
(*    This program 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 General Public License for more details.                               *)
(*                                                                               *)
(*    You should have received a copy of the GNU General Public                  *)
(*    License along with this program; if not, write to the Free Software        *)
(*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA                   *)
(*    02111-1307  USA                                                            *)
(*                                                                               *)
(*    As a special exception, you have permission to link this program           *)
(*    with the OCaml compiler and distribute executables, as long as you         *)
(*    follow the requirements of the GNU GPL in regard to all of the             *)
(*    software in the executable aside from the OCaml compiler.                  *)
(*                                                                               *)
(*    Contact: Maxence.Guesdon@inria.fr                                          *)
(*                                                                               *)
(*********************************************************************************)

(** *)

type error =
| Loc of Xtmpl.Xml.loc * exn
| Template_file_not_found of string
| Invalid_date of string * string

exception Error of error

let error e = raise (Error e)
let error_loc ?loc e =
  match loc with
    None -> raise e
  | Some loc -> error (Loc (loc, e))

let template_file_not_found ?loc file =
  error_loc ?loc (Error (Template_file_not_found file))

let rec string_of_error ?(to_string=Printexc.to_string) = function
| Template_file_not_found file ->
    Printf.sprintf "Template file not found: %s" file
| Invalid_date (str, err) ->
    Printf.sprintf "Invalid date %S:\n%s" str err
| Loc (loc, e) ->
    let str =
      match e with
        Error err -> string_of_error ~to_string err
      | Xtmpl.Rewrite.Error e -> Xtmpl.Rewrite.string_of_error e
      | Xtmpl.Xml.Error e -> Xtmpl.Xml.string_of_error e
      | _ -> to_string e
    in
    Printf.sprintf "From %s\n%s" (Xtmpl.Xml.string_of_loc loc) str

let invalid_date ?loc str err = error_loc ?loc (Error (Invalid_date (str, err)))