Hacker News new | ask | show | jobs
by benmmurphy 2540 days ago
this depends on errors being unique to the line they come from. if any of your errors overlap then it doesn't work. for example what if you have a bunch of functions that return {error, :notfound} and you want to handle each differently. also you don't have access to any previous values instantiated in the else block. if you could have an else block for each <- that short-circuited and had access to previously <- assigned values it would be perfect.
2 comments

One technique I use to solve this is to name each stage of a complex pipeline with tuple pairs. Then I can pattern match on a specific error. I've found that I haven't ever written crazy error handling and so this has worked well for me
Yeah, if your functions return the same error it's quite difficult to use the "else" pattern. I also dislike the fact that the error handling is not near the function that provokes it, but in a separate block, so you have to remember which function in the pipeline returns which error. I've never written a with-pipeline with more than 4-5 calls, so it's been easy to avoid its limitations, but I can understand it's not optimal if you're writing complex stuff.