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

Unhelpful error message when inserting a record #42

Open
tad-lispy opened this issue Jul 16, 2020 · 0 comments
Open

Unhelpful error message when inserting a record #42

tad-lispy opened this issue Jul 16, 2020 · 0 comments

Comments

@tad-lispy
Copy link

I am developing an editor for my markup documents. Perhaps I'm doing something wrong here, but the error message is not helping me understand. Here it is:

DOCUMENT DOESN'T ALLOW
You tried to insert a

    |> Card

but the block at the provided Mark.Edit.Id is expecting

    |> Card

Here is the code that generates the edit:

addCard : Mark.Edit.Id -> Mark.Parsed -> Result (List Error) Mark.Parsed
addCard id ast =
    let
        block =
            Mark.New.record "Card"
                [ ( "front", Mark.New.string "Card front content" )
                , ( "back", Mark.New.string "Card back content" )
                , ( "options", Mark.New.many [] )
                ]
                |> Debug.log "Card to be inserted"

        edit =
            Mark.Edit.insertAt id 0 block
                |> Debug.log "Edit"
    in
    Deck.update edit ast

and document definition (plus Editable a and update helpers):

document : Document
document =
    Mark.documentWith Deck
        { metadata = deckBlock
        , body = cardBlocks
        }


deckBlock : Mark.Block (Editable String)
deckBlock =
    Mark.string
        |> Mark.withId Editable
        |> Mark.block "Deck" identity


cardBlocks : Mark.Block (Editable (List Card))
cardBlocks =
    [ cardBlock ]
        |> Mark.manyOf
        |> Mark.withId Editable


cardBlock : Mark.Block Card
cardBlock =
    Mark.record "Card" Card
        |> Mark.field "front" Mark.string
        |> Mark.field "back" Mark.string
        |> Mark.field "options" optionsBlock
        |> Mark.toBlock


optionsBlock : Mark.Block (List Option)
optionsBlock =
    Mark.manyOf [ optionBlock ]


optionBlock : Mark.Block Option
optionBlock =
    Mark.record "Option" Option
        |> Mark.field "value" Mark.string
        |> Mark.field "correct" Mark.bool
        |> Mark.field "hint" Mark.string
        |> Mark.toBlock

type alias Editable a =
    { id : Mark.Edit.Id
    , value : a
    }

update : Edit -> Mark.Parsed -> Result (List Mark.Error.Error) Mark.Parsed
update edit ast =
    Mark.Edit.update document edit ast

I can try to recreate a minimal example on Ellie if you think that will help.

tad-lispy added a commit to tad-lispy/elm-markup that referenced this issue Jul 16, 2020
The bug is described in
mdgriffith#42, but I would not
consider it a fix as it does not address the error message helpfullness.

The problem is that in `ExpectManyOf` case of
`Mark.Internal.Description.matchExpected` . There are two variables
there:

    - `oneOptions` `twoOptions`

In case of updates `oneOptions` will be a list of all valid options. The
`twoOptions` will be blocks that are actually inserted.

We want to check if all inserted blocks match any of the valid options.
But it was the other way around - the test was "all valid options are
inserted". Coincidentally when there is only one valid option and at
least one block is inserted, the result is the same. That's probably why
the problem remained undetected for relatively long time. I ran into it
becasue my list was nested in a record (as described in the linked
issue) and was initially empty.
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

No branches or pull requests

1 participant