Skip to content

Unhelpful error message when inserting a record #42

Description

@tad-lispy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions