Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

9999years
Copy link

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}

Closes #91

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}
@9999years
Copy link
Author

Addressed comments, PTAL when you have some time :)

Copy link
Owner

@brandonchinn178 brandonchinn178 left a 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 ", "
Copy link
Owner

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 ", "?

Comment on lines +36 to +37
displayGraphQLError :: String -> String -> GraphQLError -> String
displayGraphQLError indentFirst indentRest exception =
Copy link
Owner

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 =
Copy link
Owner

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))
Copy link
Owner

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)?

@brandonchinn178
Copy link
Owner

Also, looks like you have some linting failures?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GraphQLError has no Exception instance
2 participants