ghcjs / ghcjs-dom

Make Document Object Model (DOM) apps that run in any browser and natively using WebKitGtk
74 stars 41 forks source link

Don't use fromJust #94

Open 3noch opened 4 years ago

3noch commented 4 years ago

We recently ran into an error where the GHCJS frontend would crash with the unhelpful console message Maybe.fromJust: Nothing. We grepped our entire dependency tree source and decided that ghcjs-dom was the most likely caller of fromJust since it uses it countless times. We were right.

The problem with fromJust is that it has no call stack at all. Even fromMaybe (error "fromJust: Nothing") would be much better because it would at least give us the immediate caller. We manually replaced all occurrences of fromJust in ghcjs-dom with something like fromMaybe (error ...) and immediately found the issue. It was one of the "*Unchecked" calls.

How hard would it be to change the code generator to use this pattern instead of using fromJust?