How do you start the web server? Who is printing the error? There are functions available in clojure.main to replicate the message from the repl - you can call them yourself. See https://clojure.org/reference/repl_and_main#_error_printing for more on error triage and the functions like Throwable>map, clojure.main/ex-triage, and clojure.main/ex-str. This chain of functions is what the REPL uses to produce the message below
On Friday, June 7, 2019 at 8:28:56 AM UTC-5, Sven Richter wrote: > > Hi, > > I just recently found out that the spec error reporting is different in > different environments. > I have the following functions: > > > (defn search-page [{:keys [off-url off-user off-password]} search] > (let [products (off/search-products search) > products-with-nutriments (mapv #(off/add-nutriments % > off/nutriments-to-extract) (:products products))] > (layout/render "off/search.html" {:products products-with-nutriments > :search search}))) > > > (defn off-routes [config] > (routes (GET "/off/search" [] (search-page config "toast")))) > > where off/add-nutriments is a specced function. Now when the spec of that > function fails and I call *search-page* from the REPL I get this output: > > Execution error - invalid arguments to off/add-nutriments at (core.clj:9). > "" - failed: #{"kJ" "kcal" "kCal" "g" "mg"} at: [:product :nutriments > :clojure.spec.alpha/pred :sugars_unit] spec: :off/unit > "" - failed: #{"kJ" "kcal" "kCal" "g" "mg"} at: [:product :nutriments > :clojure.spec.alpha/pred :fat_unit] spec: :off/unit > "" - failed: #{"kJ" "kcal" "kCal" "g" "mg"} at: [:product :nutriments > :clojure.spec.alpha/pred :salt_unit] spec: :off/unit > {:salt "3.5", :sugars_unit "", :energy-kcal "201.81514210652017", > :energy_unit "kcal", :energy_value 202, :proteins_value "17.6", > :proteins_unit "", :carbohydrates_unit "", :saturated-fat_value "8.2", :fat > 12, :energy 845, :salt_value "3.5", :saturated-fat_unit "", :fat_100g 12, > :sugars_value 6, :sodium_100g "1.37795275590551", :carbohydrates_value 6, > :proteins_100g "17.6", :fat_unit "", :saturated-fat "8.2", :sugars_100g 6, > :sodium "1.37795275590551", :sugars 6, :carbohydrates 6, :energy_100g 845, > :salt_100g "3.5", :saturated-fat_100g "8.2", :salt_unit "", > :carbohydrates_100g 6, :proteins "17.6", :fat_value 12} - failed: nil? at: > [:product :nutriments :clojure.spec.alpha/nil] spec: :off/nutriments > > which is nice and readable. > > Whereas when I run the *search-page* from the started web server through the > */off/search* route I get a stacktrace and a very unreadable output: > > clojure.lang.ExceptionInfo: Call to > #'de.sveri.getless.service.off/add-nutriments did not conform to spec. > {:clojure.spec.alpha/problems ({:path [:product :nutriments > :clojure.spec.alpha/nil], :pred nil?, :val {:salt "3.5", :sugars_unit "", > :energy-kcal "201.81514210652017", :energy_unit "kcal", :energy_value 202, > :proteins_value "17.6", :proteins_unit "", :carbohydrates_unit "", > :saturated-fat_value "8.2", :fat 12, :energy 845, :salt_value "3.5", > :saturated-fat_unit "", :fat_100g 12, :sugars_value 6, :sodium_100g > "1.37795275590551", :carbohydrates_value 6, :proteins_100g "17.6", :fat_unit > "", :saturated-fat "8.2", :sugars_100g 6, :sodium "1.37795275590551", :sugars > 6, :carbohydrates 6, :energy_100g 845, :salt_100g "3.5", :saturated-fat_100g > "8.2", :salt_unit "", :carbohydrates_100g 6, :proteins "17.6", :fat_value > 12}, :via [:de.sveri.getless.service.off/nutriments], :in [0 :nutriments]} > {:path [:product :nutriments :clojure.spec.alpha/pred :sugars_unit], :pred > #{"kJ" "kcal" "kCal" "g" "mg"}, :val "", :via > [:de.sveri.getless.service.off/nutriments > :de.sveri.getless.service.off/unit], :in [0 :nutriments :sugars_unit]} {:path > [:product :nutriments :clojure.spec.alpha/pred :fat_unit], :pred #{"kJ" > "kcal" "kCal" "g" "mg"}, :val "", :via > [:de.sveri.getless.service.off/nutriments > :de.sveri.getless.service.off/unit], :in [0 :nutriments :fat_unit]} {:path > [:product :nutriments :clojure.spec.alpha/pred :salt_unit], :pred #{"kJ" > "kcal" "kCal" "g" "mg"}, :val "", :via > [:de.sveri.getless.service.off/nutriments > :de.sveri.getless.service.off/unit], :in [0 :nutriments :salt_unit]}), > :clojure.spec.alpha/spec > #object[clojure.spec.alpha$regex_spec_impl$reify__2509 0x302765e4 > "clojure.spec.alpha$regex_spec_impl$reify__2509@302765e4"], > :clojure.spec.alpha/value ({:image_thumb_url > "https://static.openfoodfacts.org/images/products/20987664/front_de.3.100.jpg", > :_keywords ["schmelzkase" "light" "toast"], :image_small_url > "https://static.openfoodfacts.org/images/products/20987664/front_de.3.200.jpg", > :nutriments {:salt "3.5", :sugars_unit "", :energy-kcal > "201.81514210652017", :energy_unit "kcal", :energy_value 202, :proteins_value > "17.6", :proteins_unit "", :carbohydrates_unit "", :saturated-fat_value > "8.2", :fat 12, :energy 845, :salt_value "3.5", :saturated-fat_unit "", > :fat_100g 12, :sugars_value 6, :sodium_100g "1.37795275590551", > :carbohydrates_value 6, :proteins_100g "17.6", :fat_unit "", :saturated-fat > "8.2", :sugars_100g 6, :sodium "1.37795275590551", :sugars 6, :carbohydrates > 6, :energy_100g 845, :salt_100g "3.5", :saturated-fat_100g "8.2", :salt_unit > "", :carbohydrates_100g 6, :proteins "17.6", :fat_value 12}, > :ingredients_text "", :rev 10, :lang "de", :ingredients [], :id "20987664", > :code "20987664", :product_name_de "Toast Light Schmelzkäse", > :nutrition_data_per "100g", :quantity "250 g", :product_name "Toast Light > Schmelzkäse"} #object[clojure.core$partial$fn__5841 0x73f4c45a > "clojure.core$partial$fn__5841@73f4c45a"] ["energy" "fat" "saturated-fat" > "carbohydrates" "sugars" "proteins" "salt" "fiber" "cholesterol" > "monounsaturated-fat" "polyunsaturated-fat"]), :clojure.spec.alpha/fn > de.sveri.getless.service.off/add-nutriments, :clojure.spec.alpha/args > ({:image_thumb_url > "https://static.openfoodfacts.org/images/products/20987664/front_de.3.100.jpg", > :_keywords ["schmelzkase" "light" "toast"], :image_small_url > "https://static.openfoodfacts.org/images/products/20987664/front_de.3.200.jpg", > :nutriments {:salt "3.5", :sugars_unit "", :energy-kcal > "201.81514210652017", :energy_unit "kcal", :energy_value 202, :proteins_value > "17.6", :proteins_unit "", :carbohydrates_unit "", :saturated-fat_value > "8.2", :fat 12, :energy 845, :salt_value "3.5", :saturated-fat_unit "", > :fat_100g 12, :sugars_value 6, :sodium_100g "1.37795275590551", > :carbohydrates_value 6, :proteins_100g "17.6", :fat_unit "", :saturated-fat > "8.2", :sugars_100g 6, :sodium "1.37795275590551", :sugars 6, :carbohydrates > 6, :energy_100g 845, :salt_100g "3.5", :saturated-fat_100g "8.2", :salt_unit > "", :carbohydrates_100g 6, :proteins "17.6", :fat_value 12}, > :ingredients_text "", :rev 10, :lang "de", :ingredients [], :id "20987664", > :code "20987664", :product_name_de "Toast Light Schmelzkäse", > :nutrition_data_per "100g", :quantity "250 g", :product_name "Toast Light > Schmelzkäse"} #object[clojure.core$partial$fn__5841 0x73f4c45a > "clojure.core$partial$fn__5841@73f4c45a"] ["energy" "fat" "saturated-fat" > "carbohydrates" "sugars" "proteins" "salt" "fiber" "cholesterol" > "monounsaturated-fat" "polyunsaturated-fat"]), :clojure.spec.alpha/failure > :instrument, :clojure.spec.test.alpha/caller {:file "off.clj", :line 15, > :var-scope de.sveri.getless.routes.off/search-page, :local-fn fn}} > at > clojure.spec.test.alpha$spec_checking_fn$conform_BANG___3024.invoke(alpha.clj:132) > at > clojure.spec.test.alpha$spec_checking_fn$fn__3026.doInvoke(alpha.clj:140) > at clojure.lang.RestFn.invoke(RestFn.java:421) > at de.sveri.getless.routes.off$search_page$fn__32398.invoke(off.clj:15) > at clojure.core$mapv$fn__8445.invoke(core.clj:6912) > ... > > Obviously I would prefer the stacktrace and the readable output, but have no > idea how to achieve that. What is the idiomatic way to print a readable spec > explanation and a stacktrace in this context? > > Thanks, > Sven > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/b92a6f5b-182d-404b-bebf-402f0c27bcf3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.