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

Unintuitive error message when encoding is omitted #649

Closed
blowfishpro opened this issue Apr 1, 2020 · 3 comments
Closed

Unintuitive error message when encoding is omitted #649

blowfishpro opened this issue Apr 1, 2020 · 3 comments
Assignees

Comments

@blowfishpro
Copy link

Simplified example:

root = Kramdown::Element.new(:root)
root.children << Kramdown::Element.new(:text, 'stuff')
Kramdown::Converter::Kramdown.convert(root)

        2: from /Users/joey/.rvm/gems/ruby-2.6.3/gems/kramdown-2.1.0/lib/kramdown/converter/base.rb:109:in `convert'
        1: from /Users/joey/.rvm/gems/ruby-2.6.3/gems/kramdown-2.1.0/lib/kramdown/converter/base.rb:109:in `encode!'
TypeError (no implicit conversion of nil into String)

what works:

root = Kramdown::Element.new(:root, nil, nil, encoding: Encoding::UTF_8)

Now, it makes sense that an encoding is needed. But the error it produces doesn't really point to the source of the problem at all - I had to look at kramdown's source to figure out what was actually wrong.

@gettalong gettalong self-assigned this Apr 1, 2020
@gettalong
Copy link
Owner

Thanks for pointing this out. It is rather rare that someone is building an AST from scratch, so there is not much support in terms of better error messages et al. I will update the respective code to make at least this error message better.

@gettalong
Copy link
Owner

Will be in the next release.

@blowfishpro
Copy link
Author

Thanks!

For what it's worth I wasn't actually building from scratch. I was extracting part of an existing tree. But that required creating a new root.

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

No branches or pull requests

2 participants