Broken Promises

Let’s start here: Promise.resolve( 'hi' ).then( showHappy ).catch( showError )

This is a super common form you see with Promises, but is has a subtle problem. What happens if your then callback throws?

Arg! My catch caught the error! Because of how promises chain, this is expected, but often surprising. If your catch is written to expect a certain kind of error – maybe from a network request – it too could now fail.

If you want to be sure that the rejected promise is from the original promise, you have two options: use the second parameter to then, or write the catch first.

These methods have their own issues though. If the success handler really may throw, you may need to add a second catch to the end to handle that case.

And if you put the catch first, if that handler returns a non-Error, then following then will run:

That’s rarely what you want, but can be handy for cases where you want to transform an API error into a blank result.

Next time, how this all changes with async / await.

Always plan for seasonal movement

This takes seasonal movement, a common problem in woodworking, to a whole new level.

When it gets to be several degrees below freezing, the metal of the train tracks can contract to the point that it will pull up the bolts holding it in place, or even stress fracture.

Crews will soak long pieces of rope in kerosene and burn it to warm up the tracks, expanding them back into place for repairs. Once the track is warmed, it’ll be re-bolted, or welding repairs can be affected on the broken tracks.

Source: Chicago Is So Ridiculously Cold That the Railroad Tracks Need to Be on Fire to Keep the Trains Moving