Replies: 7 comments 5 replies
-
Related and soon to become obsolete PR: #1829 |
Beta Was this translation helpful? Give feedback.
-
I like most of the proposal except:
I think error types more similar to scalar types than to object types so either we should have another qualifier:
Or we drop
|
Beta Was this translation helpful? Give feedback.
-
Also note that |
Beta Was this translation helpful? Give feedback.
-
Additionally to encoding type-id and type-name into the message I think we need to encode all chain of superclasses in the error message. This is needed for the following (here is Rust, but I'm pretty sure other languages will need this too):
Actually we need two things:
Parent chain probably should also contain type names because I'd like declaring errors like this:
And this should work without extra introspection queries. So we should either make error ids derived from their qualified names or make superclass names available within the error message itself. |
Beta Was this translation helpful? Give feedback.
-
We've recently discussed if we want to support multiple inheritance of error types. Few notes:
|
Beta Was this translation helpful? Give feedback.
-
Also take a look at this trait: https://docs.rs/miette/3.2.0/miette/trait.Diagnostic.html There are subtle differences in how |
Beta Was this translation helpful? Give feedback.
-
Is this a good idea that |
Beta Was this translation helpful? Give feedback.
-
Abstract
We propose a series of changes to the current implementation of exceptions in EdgeDB. The goals include:
Specifying a binary encoding of exceptions to include additional context information about errors. The current encoding was inspired by PostgreSQL protocol and is currently undocumented.
Adding a way to raise exceptions from EdgeQL.
Exposing builtin exception types and making them introspectable.
Making it possible for EdgeDB users to define their own exceptions.
This discussion post will later be converted into an RFC.
Proposal
Error types
We propose to add a new built-in module called
errors
and a new concept of "error types":The above structure is inspired by the LSP. The idea is that the internal EdgeDB APIs once aligned with the proposed structure would enable future support of LSP right in EdgeDB itself.
The error types defined in the
errors
module, are conceptually similar to regular types, but have an additional restriction: it will not be allowed toINSERT
,UPDATE
,DELETE
, orSELECT
error types. They will only be directly usable via the newthrow
clause.The types will allow subclassing to allow users to define their own error kinds:
Since the exception types are quite different from "normal" EdgeDB object types, we propose to reflect via a separate new
schema::ErrorType
type;The "throw" clause
We propose to add a new "throw" clause to EdgeQL allowing users to raise exceptions; example:
The clause would return a new bottom-type called
never
. It is a subtype of, and assignable to, every type; however, no type is a subtype of, or assignable to,never
.This allows users to implement runtime-assertions, as in:
Implementation
Continue using PostgreSQL exceptions as the base mechanism.
In binary, exceptions will be encoded the same way as regular data messages. The
ErrorResponse
protocol message will include both a type descriptor and an encoded specific error.For exceptions constructed in runtime we will construct the type descriptor during compilation, and the actual error data in runtime (via the
SELECT record_send(row('myerror', 'foo'));
kind of SQL query).Serialized exceptions will include implicit
__tname__
(fully qualified error type name) and__tid__
(error type id) properties.Backwards Compatibility
This will be a backwards-incompatible change on the protocol level. The high-level client code and EdgeQL queries will continue working as before.
Beta Was this translation helpful? Give feedback.
All reactions