biscuit

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit d69b7b8355737b7adb56bbf00c1ae5acfa519df0
parent 1652fefab72c92e892becda3d844c0dbd0e2bc9e
Author: Daniel Barlow <dan@telent.net>
Date:   Tue, 10 Mar 2026 00:14:39 +0000

handle json deciding errors

Diffstat:
Mpkgs/maps/tiles.fnl | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/pkgs/maps/tiles.fnl b/pkgs/maps/tiles.fnl @@ -135,13 +135,20 @@ (fn tile-name [x y zoom] (.. x "_" y "_" zoom)) +(fn jsond [s] + (case (pcall json.decode s) + (true val) val + (false err) (values nil err))) + (fn fetch [cq x y zoom cb] (let [k (tile-name x y zoom) pathname (.. "/tmp/tiles/" k ".json")] (if (file-exists? pathname) (let [payload (with-open [i (io.open pathname :r)] (i:read "*a"))] (when (not (= payload "")) - (cb (canvas (. (json.decode payload) :elements) zoom)))) + (case (jsond payload) + val (cb (canvas (. val :elements) zoom)) + (nil err) (print "json decode error" pathname)))) (let [out (io.open pathname :w)] (cq:wrap (fn [] (print "getting " k) @@ -154,7 +161,9 @@ (cqueues.sleep (math.random 2 6)))) (print "got " k) (f:write payload) - (cb (canvas (. (json.decode payload) :elements) zoom)) + (case (jsond payload) + val (cb (canvas (. val :elements) zoom)) + (nil err) (print "json decode error" pathname)) true))))))) { : fetch : latlon->tile :name tile-name }