Open harold opened 5 years ago
Hi @harold. Thanks for reporting this issue, and for the kind feedback.
I fully agree; There's definitely a need for some improved error handling. A few others have hit this wall as well. I've changed the issue title to reflect this.
Thanks again
Ok, it looks like one possible path forward is to do what the vega editor does:
https://github.com/vega/editor/blob/master/src/utils/validate.ts
Which uses ajv, which appears to be available from cljsjs: https://github.com/cljsjs/packages/tree/master/ajv
Not sure if the schema is accessible from the vega-lite package in use, but it could likely be acquired from somewhere.
In this case, the errors are still pretty unhelpful:
Additionally, something like this in the implementation of oz.core
may be helpful:
diff --git a/src/cljs/oz/core.cljs b/src/cljs/oz/core.cljs
index 13508c8..b8cb087 100644
--- a/src/cljs/oz/core.cljs
+++ b/src/cljs/oz/core.cljs
@@ -26,7 +26,12 @@
(let [spec (clj->js spec)
opts {:renderer "canvas"
:mode "vega-lite"}
- vega-spec (. js/vl (compile spec))]
+ vega-spec (try
+ (. js/vl (compile spec))
+ (catch js/Error e
+ (println "Compile failed, JSON spec was:")
+ (log spec)
+ (throw e)))]
(log "Vega-lite translates to:")
(log vega-spec)
(-> (js/vegaEmbed elem spec (clj->js opts))
@@ -86,5 +91,3 @@
(reduce merge (rest x))]
x))
spec))
I kind of wanted to print the spec as JSON with (js/JSON.stringify spec nil 2)
so I could paste it right into the vega editor --- but that's not really tenable if there is nontrivial data.
That seems pretty reasonable. I could be wrong, but I believe vl
does expose the schema.
Thanks again
Hi, first, thanks for Oz, having great and powerful viz in Clojure is a good thing and I appreciate your efforts.
Using
(oz/start-plot-server!)
I had a spec like:
data
andk
were good...And when I did
(oz/view!)
the webpage disappeared (went completely blank) and this was in the console:It took me just a minute to figure out that
:vaules
was misspelled, but having a nicer error in this case would be great.Thanks again, and keep up the good work.