Convex Errors types
im getting no type defs for
ConvexError
?
The types for the class are weird?6 Replies
@CodingWithJamal what version of Convex do you have installed? Can you say more about "no type defs," what are you expecting?
Is this about what you get when you command-click in VS Code?
I'd also like to hear more about the types for the class being weird, maybe this is the generic?
1.3.1
and im saying in the news postyou show and example of:
So i was expecting when i click message in my ide to be taken to the types but nothing happens. And also for the
severity
what are the other options? Should it not be like:
severity: "FATAL" | "WARN" etc.. in the source code?
how do i know the other options than FATAL?Ah ok, yeah unfortunately clicking on an error does not jump to the source where it was defined — there are some subclassing approaches we looked at that could make this work, but inheritence / instanceof checks are tricky over the wire.
Re
severity: "FATAL" | "WARN" etc.. in the source code?This is arbitrary data, it's just an example; if a field called
severity
is useful to you you can add it to errors, but there's nothing special about any field in a ConvexError except for message
OK this makes sense, the reason these are missing is that ConvexError doesn't require any options. If you define your own types or subclasses of ConvexError
, those can have specific types, but be very careful not to use instanceof
when checking for these.I see, so is ConvexErrors only main function just to give the client contex to errors from the server side? Other than that its a wrapper for native
Error
typeSomething like
would let these by typed: when you handle them, you can check
kind
to know what data to expect
That's right, the difference between a normal error and a ConvexError is that only ConvexErrors get this data passed back to the client. The names of normal errors or the data attached might leak secret information to clients, so this needs to be an explicit choice.okay thanks for the information!