~subsetpark/bagatto

bagatto/src/error.janet -rw-r--r-- 2.5 KiB
4fc04b3a — Zach Smith Add render some 2 months ago
                                                                                
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
(defn- f-name [f] (or (disasm f :name) "f"))

(defn- error-context [k] ((dyn :error-context) k))
(defn- spec-name [] (string (error-context :spec-name)))

(defn- format-renderer-context
  []
  (let [cxt (error-context :render-context)]
    (if (any? [cxt])
      (string/format
        ```
       
Current render context:
%q
       ```
        cxt)
      "")))

(defn eval-error
  [sym filename]
  (string "Expected symbol " sym "; couldn't be found after evaluating " filename))

(defn path-error
  [err f args-type]
  (string/format
    ```

Encountered error generating path for site spec %s:
             
%s.

Expected path function signature:
(defn %s %s "foo/bar/...")
             ```
    (spec-name)
    err
    (f-name f)
    (case args-type :d "[data]" :di "[data item]")))

(defn renderer-error
  [err f args-type]
  (string/format
    ```

Encountered error rendering output for site spec %s:

%s.
%s
Expected renderer function signature:
(defn %s %s "<html>...")
             ```
    (spec-name)
    err
    (format-renderer-context)
    (f-name f)
    (case args-type :d "[data]" :di "[data item]")))

(defn attrs-error
  [err attrs-f]
  (string/format
    ```

Encountered error getting attrs for data spec %s:

%s.

Expected parse function signature:
(defn %s [src attrs] attrs)
          ```
    (spec-name)
    err
    (or (disasm attrs-f :name) "f")))

(defn data-error
  [spec]
  (error (string/format
           ```

Received invalid data spec: %q

Specification can be one of the following:
{:src (loader|path) :attrs parser)}
{:attrs attrs}
          ```
           spec)))

(defn site-error
  [spec]
  (error (string/format
           ```

Received invalid site spec: %q

Specification can be one of the following:
{:each site-selector :dest path-generator :out renderer} (write)
{:each site-selector :dest path-generator} (copy)
{:dest (path|path-generator) :out (contents|renderer)} (write)
{:some site-selector :dest (path|path-generator)} (copy)
          ```
           spec)))

(defn loader-spec-error
  [spec-name f]
  (string/format
    ```

Received invalid loader for data spec: %q

Got: function %s, arity %q;

Loader should return either:

{:each file-spec-sequence}
{:some single-file-spec}
          ```
    spec-name
    (f-name f)
    ((disasm f) :arity)))

(defn copy-error
  [spec-name selector item]
  (error (string/format
           ```
          
Attempted to generate a copy instruction for site spec: %q

In data at %q, expected :

{:path <from path>}

Got:

%q
          ```
           spec-name
           selector
           item)))