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

dhall-json: Throw error when union value is incompatible with Inline nesting #1226

Merged
merged 2 commits into from
Aug 20, 2019

Conversation

sjakobi
Copy link
Collaborator

@sjakobi sjakobi commented Aug 9, 2019

No description provided.

\ \n\
\The following Dhall expression could not be translated to JSON: \n\
\ \n\
\↳ " <> Core.pretty record <> " \n\
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pretty-printing here (and probably in the other errors too) needs improvement. Currently it looks like this:

The following Dhall expression could not be translated to JSON:                 
                                                                                
↳ { contents = < Left : { foo : Natural } | Middle : Natural | Right : { bar : Bool } >.Middle 0, field = "name", nesting = < Inline | Nested : Text >.Inline }                                                  
                                                                                
... because                                                                     
                                                                                
↳ 0                                     
                                                                                
... is not a record.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Dhall.Util.insert, which is the same thing type-checking error messages use:

-- | Function to insert an aligned pretty expression
insert :: Pretty a => a -> Doc Ann
insert expression =
"" <> Pretty.align (snipDoc (Pretty.pretty expression))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'm using Dhall.Util.insert now. I had to expose Dhall.Util from dhall though. I hope that's ok.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine

\ \n\
\The following Dhall expression could not be translated to JSON: \n\
\ \n\
\↳ " <> Core.pretty record <> " \n\
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Dhall.Util.insert, which is the same thing type-checking error messages use:

-- | Function to insert an aligned pretty expression
insert :: Pretty a => a -> Doc Ann
insert expression =
"" <> Pretty.align (snipDoc (Pretty.pretty expression))

@sjakobi sjakobi changed the title WIP: dhall-json: Throw error when union value is incompatible with Inline nesting dhall-json: Throw error when union value is incompatible with Inline nesting Aug 10, 2019
@mergify mergify bot merged commit 93711ae into master Aug 20, 2019
@mergify mergify bot deleted the sjakobi/inline-error branch August 20, 2019 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants