Ziggit

Tagged union wrapped in error union vs. errors in tagged union? (opens in new tab)

Ordinary errors can’t have additional data, so you have to return a tagged union instead of an error union. But what if of the possible errors of a function, only some have additional data and some are ordinary errors? For example, think of a CLI parser that can fail because of invalid input (which will return diagnostics about which input argument was bad) or because memory allocation failed. I could just return a tagged union, and include the ordinary error set in it, but returning errors t...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help