git.s-ol.nu mmm / 74e6bb9
better error-handling / logging s-ol 2 years ago
9 changed file(s) with 26 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
7272 local store = web.WebStore({ verbose = true })
7373 local root = fileder.Fileder(store, store:get_index(nil, -1))
7474
75 BROWSER = browser.Browser(root, path, facet, true)
75 local err_and_trace = function (msg) return debug.traceback(msg, 2) end
76 ok, BROWSER = xpcall(browser.Browser, err_and_trace, root, path, facet, true)
77 if not ok then error(BROWSER) end
7678 end)
7779 </script>"
7880 else if not fileder\has_facet facet.name
8789 else
8890 501, "not implemented"
8991
92 err_and_trace = (msg) -> debug.traceback msg, 2
9093 stream: (sv, stream) =>
9194 req = stream\get_headers!
9295 method = req\get ':method'
101104 type = type\match '%s*(.*)'
102105 facet = Key facet, type
103106
104 ok, status, body = pcall @.handle, @, method, path, facet
107 ok, status, body = xpcall @.handle, err_and_trace, @, method, path, facet
105108 if not ok
106 warn status, body
107 body = "Internal Server Error: #{status}"
109 warn "Error handling request (#{method} #{path} #{facet}):\n#{status}"
110 body = "Internal Server Error:\n#{status}"
108111 status = 500
109112
110113 res = headers.new!
1414 val
1515 else
1616 error "not a Node: #{val}, #{type val}"
17
18 fromhtml = (node) -> :node
1719
1820 -- shorthand to form a text node from a string
1921 text = (str) -> document\createTextNode tostring str
145147 :get_or_create,
146148 -- :join,
147149 :tohtml,
150 :fromhtml,
148151 :text,
149152 :elements,
150153 }
1414 val
1515 else
1616 error "not a Node: #{val}, #{type val}"
17
18 fromhtml = (html) -> render: -> html
1719
1820 -- shorthand to form a text node from strings
1921 escapes = {
127129 :ReactiveElement,
128130 :get_or_create,
129131 :tohtml,
132 :fromhtml,
130133 :text,
131134 :elements,
132135 }
99 return tbl if 'userdata' == type tbl
1010
1111 buf = space .. tostring tbl
12 return buf unless 'table' == type tbl
12 return buf unless 'table' == (type tbl) or table.__tostring
1313
1414 buf = buf .. ' {\n'
1515 for k,v in pairs tbl
33 deep_tostring = (tbl, space='') ->
44 buf = space .. tostring tbl
55
6 return buf unless 'table' == type tbl
6 return buf unless 'table' == (type tbl) or tbl.__tostring
77
88 buf = buf .. ' {\n'
99 for k,v in pairs tbl
165165 @node = wrapper.node
166166 @render = wrapper\render
167167
168 err_and_trace = (msg) -> { :msg, trace: debug.traceback! }
168 err_and_trace = (msg) -> debug.traceback msg, 2
169169 default_convert = (key) => @get key.name, 'mmm/dom'
170170
171171 -- render #browser-content
176176 if MODE == 'CLIENT'
177177 err\set pre msg
178178 warn "ERROR rendering content: #{msg}"
179 nil
179 div!
180180
181181 active = @active\get!
182182
192192 res
193193 elseif ok
194194 div "[no conversion path to #{prop.type}]"
195 elseif res and res.msg.match and res.msg\match '%[nossr%]$'
195 elseif res and res\match '%[nossr%]'
196196 div "[this page could not be pre-rendered on the server]"
197197 else
198 res = "#{res.msg}\n#{res.trace}"
199198 disp_error res
200199
201200 get_inspector: =>
7676 -- * value - value
7777 -- * ... - other transform parameters (fileder, key)
7878 -- returns converted value
79 err_and_trace = (msg) -> debug.traceback msg, 2
7980 apply_conversions = (conversions, value, ...) ->
8081 for i=#conversions,1,-1
8182 step = conversions[i]
82 value = step.convert.transform step, value, ...
83 ok, value = xpcall step.convert.transform, err_and_trace, step, value, ...
84 if not ok
85 f, k = ...
86 error "error while converting #{f} #{k} from '#{step.from}' to '#{step.to}':\n#{value}"
8387
8488 value
8589
126126 nolink = js_fix element\getAttribute 'nolink'
127127 inline = js_fix element\getAttribute 'inline'
128128 desc = js_fix element.innerText
129 desc = nil if desc == ''
129130
130131 element\replaceWith embed path or '', facet or '', fileder, { :nolink, :inline, :desc }
131132
238239 {
239240 inp: '(.+)',
240241 out: 'URL -> %1',
241 cost: 10
242 cost: 5
242243 transform: (_, fileder, key) => "#{fileder.path}/#{key.name}:#{@from}"
243244 }
244245 {
8080 coroutine.yield facet.name, facet.type
8181
8282 load_facet: (path, name, type) =>
83 @log "loading facet #{path} #{name}: #{type}"
8384 fetch "#{@host .. path}/#{name}: #{type}"
8485
8586 create_facet: (path, name, type, blob) =>