-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve exception display for GraphQLException
and GraphQLError
#92
base: main
Are you sure you want to change the base?
Conversation
Before: GraphQLException [GraphQLError {message = "Something went wrong!", locations = Just [GraphQLErrorLoc {errorLine = 10, errorCol = 3}], path = Just [String "my_query.graphql"], extensions = Just (Object (fromList [("complexity",Number 2.0)]))}] After: GraphQL errors: At 10:3: Something went wrong! Path: "my_query.graphql" Extensions: {"complexity":2}
Addressed comments, PTAL when you have some time :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sigh if only we had string interpolation 🙂
Just a couple more minor issues
<> maybe "" (nextLine "Path: " . joinWithCommas . map valueToString) (path exception) | ||
<> maybe "" (nextLine "Extensions: " . valueToString) (extensions exception) | ||
where | ||
joinWithCommas = unwords . intersperse ", " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem right; wouldn't it do
["a", "b"] => "a , b"
Shouldn't it just be intercalate ", "
?
displayGraphQLError :: String -> String -> GraphQLError -> String | ||
displayGraphQLError indentFirst indentRest exception = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I don't think this needs to be completely general 🙂 Let's just inline "* "
and " "
; I suspect it'll be a bit cleaner
@@ -30,13 +33,35 @@ data GraphQLError = GraphQLError | |||
} | |||
deriving (Show, Eq, Generic, ToJSON, FromJSON) | |||
|
|||
displayGraphQLError :: String -> String -> GraphQLError -> String | |||
displayGraphQLError indentFirst indentRest exception = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: to avoid all the parentheses, maybe RecordWildCard the exception
?
displayGraphQLError indentFirst indentRest exception = | ||
indentFirst | ||
<> "At " | ||
<> joinWithCommas (maybe [] (map displayErrorLoc) (locations exception)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An empty list would make the message a bit weird. Can we maybe show ???
if there's no location (either Nothing or an empty list in locations
)?
Also, looks like you have some linting failures? |
Before:
After:
Closes #91