The Holy Java

Building the right thing, building it right, fast

ClojureScript/Om: Spurious “Minified exception occured” With Advanced Optimizations

Posted by Jakub Holý on May 13, 2014

After having upgraded to Om 0.6.3. and ClojureScript 2197, I suddenly got the following error in the browser when loading the .js compiled with :optimizations :advanced:

Uncaught Error: Minified exception occured; use the non-minified dev environment for the full error message and additional helpful warnings.

In the dev mode, i.e. without any optimizations, the code worked just fine – the same thing that Frozenlock has experienced.

After downgrading, removing Om, and upgrading again it suddnely dissapeared and now Om 0.6.3. and ClojureScript 2197 work just fine. So I suppose that after having changed the versions, I should have properly deleted all generated files (and not just my myapp.min.js).

I hope this helps to somebody.

Posted in Languages | Tagged: , | Comments Off

core.async: “Can’t recur here” in ClojureScript but OK in Clojure

Posted by Jakub Holý on May 12, 2014

With the latest core.async and ClojureScript (core.async "0.1.303.0-886421-alpha" and clojurescript "0.0-2202" as well as the older core.async "" and clojurescript "0.0-2173"), the following function compiles just fine in Clojure but fails in ClojureScript:

(defn cljs-cannot-recur! []
  (go-loop [v nil]
    (when-let [next-val (<! (timeout 300))]
      (recur next-val))))

The error in ClojureScript is

clojure.lang.ExceptionInfo: Can't recur here at line 23 /my/path/core.cljs ::
  {:tag :cljs/analysis-error, :file "/my/path/core.cljs", :line 23, :column 7}
             core.clj:4403 clojure.core/ex-info
             ... // very long stacktrace of 0 value

Workaround: replace (go-loop ..) with (go (loop ..)).

Another fun fact: ClojureScript’s core.async lacks (at least) alt! (I did work around it by using alts! so it is not a show-stopper but still the difference is irritating and I fail to understand why it is missing.)

Oh, joy!

Posted in Languages | Tagged: | Comments Off

Graphite Shows Metrics But No Data – Troubleshooting

Posted by Jakub Holý on May 5, 2014

My Graphite has all the metrics I expect but shows no data for them. Communication between my app and Graphite clearly works otherwise the metrics would not have appeared in the list but why is there no data?

Update: Graphite data gotchas that got me

(These gotchas explain why I did not see any data.)

  1. Graphite shows aggregated, not raw data if the selected query period (24h by default) is greater than the retention period of the highest precision. F.ex. with the schema “1s:30m,1m:1d,5m:2y” you will see data at the 1s precision only if you select period less than or equal to the past 30 minutes. With the default one, you will see the 1-minute aggregates. This applies both to the UI and
  2. Aggregation drops data unless by default at least 50% of available data slots have values (xFilesFactor=0.5). I.e. if your app sends data at a rate more than twice slower than Graphite expects them, they will never show up in aggregates. F.ex. with the schema “1s:30m,1m:1d,5m:2y”  you must sends data at least 30 times within a minute for them to show in an aggregate.

I suppose that would show the raw data.

Lesson learned: Always send data to Graphite in *exactly* same rate as its highest resolution

As described above, if you send data less frequently than twice the highest precision (if 1s => send at least every 2s), aggregation will ignore the data, with the default xFilesFactor=0.5 (a.k.a. min 50% of values reqired factor). On the other hand, if you send data more frequently than the highest precision, only the last data point received in each of the highest precision periods is recorded, others ignored – that’s why f.ex. statsD flush period must = Graphite period.

Read the rest of this entry »

Posted in Tools | Tagged: , | Comments Off

Most interesting links of April ’14

Posted by Jakub Holý on April 30, 2014

Recommended Readings

  • The economics of reuse – developing code for reuse costs much more than for one need – it might cost 300% more to develop and save you 75% of work when (re)using it instead of developing from scratch (if one of the factors goes down, the other one typically goes down too). Summary: “That means that to get any value from your reused component, you better have five or more reusers or you have to find a way to substantially improve the [reuse value factor] or [reusability cost factor]. Very smart people have failed to do this.
  • Book in making: Reactive Design Patterns (1st ch free)

Sharing data on the web

Clojure Corner

  • 8th Light: Combining Clojure and ClojureScript Libraries (3/2014) – really good and detailed article / tutorial using CLJX and platform-specific platform.clj[s] files to share code between Clojure and ClojureScript. It also recommends a file structure (src/(clj|cljs)/), demonstrates testing, discusses macro development, shows how to pack both into one jar.


Favourite Quotes

Posted in General, Languages, Top links of month | Tagged: , , , , | Comments Off

Clojure: How To Prevent “Expected Map, Got Vector” And Similar Errors

Posted by Jakub Holý on April 30, 2014

What my Clojure code is doing most of the time is transforming data. Yet I cannot see the shape of data being transformed – I have to know what the data looks like on the input and hold a mental model of how they change at each step. But I make mistakes. I make mistakes in my code so that the data does not correspond anymore to the model it should follow. And I make mistakes in my mental model of what the data currently looks like, leading likely to a code error later on. The end result is the same – a little helpful exception at some later step regarding wrong shape of data. There are two problems here: The error typically provides too little useful information and it usually manifests later than where the code/model mistake actually is. I therefore easily spend an hour or more troubleshooting these mistakes. In addition to that, it is also hard to read such code because a reader lacks the writer’s mental model of the data and has to derive it herself – which is quite hard especially if the shape of the input data is not clear in the first place.

I should mention that I of course write tests and experiment in the REPL but I still hit these problems so it is not enough for me. Tests cannot protect me from having a wrong model of the input data (since I write the [unit] tests based on the same assumptions as the code and only discover the error when I integrate all the bits) and even if they help to discover an error, it is still time-consuming the root cause.

Can I do better? I believe I can.

Read the rest of this entry »

Posted in Languages | Tagged: | 8 Comments »

How to create and run Gatling 2.0 tests

Posted by Jakub Holý on April 28, 2014

Getting up and running with Gatling perf. tests as I would like so I record this for my future reference.

0. Create a project:

$ mvn archetype:generate \

(The trailing “:” in the filter is important.)

1. Import to IntelliJ

In IntelliJ choose to import an object, instead of “from sources” select “from external model” and then Maven. You will also need to have the Scala plugin installed and, when imported, you will likely need to right-click on pom.xml and Maven – Reimport.

2. Record a simulation

  1. Run the src/test/scala/Recorder.scala (right-click – Run ‘Recorder’)
  2. Set the port it should listen on, f.ex. 8000 (maybe you also need to set port for HTTPS, f.ex. 8001), set the target app (perhaps localhost, <some port>, <some https/dummy port>)
  3. Optionally set the class name of the recorded simulation and the target package (the output goes to src/test/scala/<package>/<name>.scala)
  4. Click [Start !]
  5. Go to your browser and configure it to use the recorder as its HTTP[s] proxy
  6. Browse localhost:8000/your_app as you want for the test
  7. Click [Stop and save] in the Recorder UI

Read the rest of this entry »

Posted in Testing, Tools | Tagged: , | Comments Off

Kioo: How to Troubleshoot Template Processing

Posted by Jakub Holý on April 8, 2014

So you have created an Om/Reagent/React component using a Kioo template and the result is not as you expected, perhaps just an empty element? Let me share what I have discovered about troubleshooting this (though I am no expert). You will se how to invoke the underlying Clojure function component* manually, how to expand the deftemplate macro, how to call the resulting JavaScript function, and what the intermediate forms look like.

Read the rest of this entry »

Posted in Languages | Tagged: , , | 3 Comments »

Kioo: How To Replace The Whole Body

Posted by Jakub Holý on April 8, 2014

This whole post in unnecessary since it is simply possible to use a snippet directly without a template, as kindly explained by Creighton Kirkendall.

Kioo, the enlive-inspired templating library for React.js and derived libs such as Om, normally works by matching selectors against elements inside <body> and transforming the matched elements while also keeping all the other ones. But what if you want to keep just the single matched element and drop all the others? You need some tricks and I will demonstrate one possible way.

Dislaimer: This is a result of my experimentation, not deep knowledge if Kioo.

Read the rest of this entry »

Posted in Languages | Tagged: , | Comments Off

Most interesting links of March ’14

Posted by Jakub Holý on March 31, 2014

Recommended Readings

Clojure Corner

  • Timo Mihaljov’s Pimp My REPL (3/2014)- really great tips – user.clj, :dev profile, user-wide config in .lein/profiles.clj, tools.namespace, making funs available everywhere & more via Vinyasa, form println with Spyscope, debug-repl, difform, clj-ns-browser


  • clj-ds – Clojure immutable datastructures extracted from Clojure and made easier for use directly in Java

Favourite Quotes

Posted in General, Top links of month | Tagged: | Comments Off

Framework Joy: Load in Hibernate Updates Data

Posted by Jakub Holý on March 31, 2014

Would you ever guess that this line

// Load Buyer from DB by id using Spring's HibernateTemplate:
final Buyer traveller = (Buyer) hibernateTemplate.load(Buyer .class, new Long(id));

could lead to a constraint-validation exception during a batch update or delete and re-insert rows (loosing all columns Hibernate does not know about)? I was quite surprised.

In particular buyer’s bonusCards get deleted and re-inserted, because Hibernate believes that the collection of cards is dirty, even though it has just loaded it from the DB. I am not exactly sure why (preventing false positives in dirty checks requires some black magic), this is the configuration:

<class name="Buyer" ...>
    <set name="bonusCards " table="bonus_cards">
        <key column="buyer_id"/>
        <composite-element class="BonusCard">
            <property name="number" column="number" not-null="false"/>
            <property name="expiredate" column="expdate"/>

Of course Hibernate certainly has good reasons to update and delete+re-insert data upon load and we could certainly get rid of (some of) these updates by configuring Hibernate better. But it still demonstrates nicely the hidden cost of using a complex framework – in this case, it behaves quite unexpectedly and requires extensive knowledge to set up properly and to troubleshoot.

Posted in j2ee | Tagged: | Comments Off