Replies: 2 comments 5 replies
-
|
I don't like the default throwing. I use orchid in a graphql server and I return my errors as objects, so I don't want to throw a random error. I always end up having to reach for "optional" so I can then manually return a specific object type. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I found many ORMs provide two methods, In my developing experience, I found there are some cases I do not want a default throw, |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, methods like
find,take,findBy,getare throwing when no records found.And this enables more concise code:
Also, it works in a same way when it's used inside
select. The following code will throw if there is no related record:Does this feel unexpected? Would you prefer more explicit
OrThrow:So on one hand,
findis concise and looks neat,findOrThrowcreates visual noise. And, in my opinion, throwing by default is preferred as you don't have to think about thenot foundcase. On other hand,findOrThrowis more obvious and forces user to think if they really want a throw here or if they shouldfindOptional.Perhaps, the best way here is to allow customizing this.
6 votes ·
Beta Was this translation helpful? Give feedback.
All reactions