swiftlang/swift-markdown

Fatal error: Unknown cmark node type 'attribute'

gfinger opened this issue · 2 comments

Initializing a Document with a string containing custom attributes like
^[bla](xyz: 'abc')
bringsup a fatal error: Markdown/CommonMarkConverter.swift:139: Fatal error: Unknown cmark node type 'attribute' encountered during conversion`.
Entering any text as input for a Document must never end up in a fatal error. The Document is often directly initialised from a user input, which must never stop the execution of the program. A simple fix would just ignore all unknown node types.

This specific issue should be fixed by #25.

I do agree that it's worth not crashing over unknown elements from cmark. However, it's still worth knowing when something is wrong rather than just dropping things silently. I wonder if it would be worth adding a debug assertion instead of a fatal error? That way release builds of Swift-DocC (or other programs that use Swift-Markdown) won't crash, but debug builds will have more information. Does that sound alright?

The expression
^[bla](xyz: 'abc')
is a completely legitimate user input and must in no way lead to a crash of the program. If it does, it is a programming error. To check for programming errors assertions could be one means. For example you could check the pre- and post-conditions of a function call using assertions. In the specific case here a simple unit test might be the better solution.
I think the fix #25 addresses my wish to see swift-markdown supporting CustomAttributes. I'm looking forward to have it in the main branch.