Hello all! Was having a discussion with @lofty storm regarding the usage of Errors in the Blend Protocol and wanted to move the convo to a public location.
Context:
]leigh: I'd like to understand how you're currently using errors.
[2:49 PM]leigh: As well as hear more about the issues you've come across, ambiguity about how to use them, which options to pick, etc.
[2:49 PM]leigh: No feedback is too small in this area.
[3:10 PM]mootz12: The feedback I mostly had was it wasn't clear to me how errors were intended to be used while writing contracts, and by extension consuming them.
Contracts currently have the ability to return a Result<thing, Error> or thing. Either way, the Client that gets generated on consumption is the same. It makes it unclear if a contract supports returning Errors or not. By habit I return Result<thing, error> if I ever expect my contract call to be handled on failure, and thing if I don't (which, to be fair, is only in the case of view functions).
I think the expectation gets further obfuscated with the pattern of panic_with_error macro and the auto try_ functions. (This could be thrown from anywhere in the codepath, and isn't really identifiable from the contract entry point)
I don't think the Blend protocol handles errors in a consistent or smart way TBH. The initial idea was consistent, unique codes for error groups (like http status codes). I'd have some hope the community could adopt standards for error codes (like, 403 Forbidden if the TX is signed validly but from an address that doesn't have enough privilege). The primary goal here would be to hopefully decode the problem of getting Result(ContractError(3)) and having no idea what that means, or what contract threw this error.