3 ms·
It’s not just syntax, there are semantic problems. Like, function 1 fails for reason A or B. Function 2 fails for A or C. You call both functions. How do you p
by klodolph 1y ago
It’s not just syntax, there are semantic problems.
Like, function 1 fails for reason A or B. Function 2 fails for A or C. You call both functions. How do you pattern match on reason A, in the result of your function?
In Go, there’s a somewhat simple pattern for this, which is errors.Is().
- Expurple 1y agoIt's a tradeoff. When you have a "flat" union like `A | B | C` that makes it easy to pattern-match "leaf" errors, you give up the ability to add any additional context in function1 and function2. Although, there are workarounds like struct Error { leaf_error: A | B | C, context: Vec<String>, }