Struct vs Enum for Error Types

One big disadvantage to using enums for errors is that if you're developing standard built-from-source packages (i.e., not using library evolution and distributing something as a prebuilt library), adding a new case to the enum is a source-breaking change for your clients because they could theoretically be switching exhaustively over them. So instead, you have to introduce new separate enums to represent new failure modes in the future. This limitation is one of the motivations behind pitches like this one.

6 Likes