htdebeer / pandocomatic

Automate the use of pandoc

Home Page:https://heerdebeer.org/Software/markdown/pandocomatic/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined method `has_key?' for nil:NilClass (NoMethodError) since v 0.2.0.5

agusmba opened this issue · comments

I'm experiencing an error when upgrading pandocomatic to anything above v0.2.0.5:

$ gem install pandocomatic --pre
Fetching: paru-0.3.2.0.gem (100%)
Successfully installed paru-0.3.2.0
Fetching: optimist-3.0.0.gem (100%)
Successfully installed optimist-3.0.0
Fetching: pandocomatic-0.2.5.0.alpha.gem (100%)
Successfully installed pandocomatic-0.2.5.0.alpha
Parsing documentation for paru-0.3.2.0
Installing ri documentation for paru-0.3.2.0
Parsing documentation for optimist-3.0.0
Installing ri documentation for optimist-3.0.0
Parsing documentation for pandocomatic-0.2.5.0.alpha
Installing ri documentation for pandocomatic-0.2.5.0.alpha
Done installing documentation for paru, optimist, pandocomatic after 7 seconds
3 gems installed

$ pandocomatic --data-dir=res -b -i src/document.md -o build/document.docx
An unexpected error has occurred. You can report this bug via https://github.com/htdebeer/pandocomatic/issues/new.
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/pandocomatic-0.2.5.0.alpha/lib/pandocomatic/configuration.rb:377:in `block in set_destination': undefined method `has_key?' for nil:NilClass (NoMethodError)
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/pandocomatic-0.2.5.0.alpha/lib/pandocomatic/configuration.rb:397:in `set_destination'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/pandocomatic-0.2.5.0.alpha/lib/pandocomatic/command/convert_file_command.rb:77:in `initialize'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/pandocomatic-0.2.5.0.alpha/lib/pandocomatic/command/convert_file_multiple_command.rb:60:in `new'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/pandocomatic-0.2.5.0.alpha/lib/pandocomatic/command/convert_file_multiple_command.rb:60:in `block in initialize'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/pandocomatic-0.2.5.0.alpha/lib/pandocomatic/command/convert_file_multiple_command.rb:57:in `each'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/pandocomatic-0.2.5.0.alpha/lib/pandocomatic/command/convert_file_multiple_command.rb:57:in `initialize'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/pandocomatic-0.2.5.0.alpha/lib/pandocomatic/pandocomatic.rb:77:in `new'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/pandocomatic-0.2.5.0.alpha/lib/pandocomatic/pandocomatic.rb:77:in `run'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/pandocomatic-0.2.5.0.alpha/bin/pandocomatic:3:in `<top (required)>'
        from C:/Ruby24-x64/bin/pandocomatic:23:in `load'
        from C:/Ruby24-x64/bin/pandocomatic:23:in `<main>'

In order to isolate it from my windows box, I also used a docker image:

$ docker run --rm -it -v /$(pwd):/source               -v /$(pwd)/res:/root/.pandoc               agusmba/pandocomatic pandocomatic --data-dir=res -b               -i
src/document.md               -o build/document.docx
An unexpected error has occurred. You can report this bug via https://github.com/htdebeer/pandocomatic/issues/new.
Traceback (most recent call last):
        10: from /usr/local/bin/pandocomatic:23:in `load'>'
         8: from /var/lib/gems/2.5.0/gems/pandocomatic-0.2.4.1/lib/pandocomatic/pandocomatic.rb:100:in `run'
         6: from /var/lib/gems/2.5.0/gems/pandocomatic-0.2.4.1/lib/pandocomatic/command/convert_file_multiple_command.rb:57:in `initialize'
         4: from /var/lib/gems/2.5.0/gems/pandocomatic-0.2.4.1/lib/pandocomatic/command/convert_file_multiple_command.rb:60:in `block in initialize'
         2: from /var/lib/gems/2.5.0/gems/pandocomatic-0.2.4.1/lib/pandocomatic/command/convert_file_command.rb:77:in `initialize'w'
         1: from /var/lib/gems/2.5.0/gems/pandocomatic-0.2.4.1/lib/pandocomatic/configuration.rb:256:in `set_destination'
/var/lib/gems/2.5.0/gems/pandocomatic-0.2.4.1/lib/pandocomatic/configuration.rb:236:in `block in set_destination': undefined method `has_key?' for nil:NilClass (NoMethodError)

Ok the problem seems to be related to the yaml frontmatter in my markdown document. In particular to commented out lines under the pandoc section:

---
pandocomatic_:
    use-template:
        - my-word-template
    pandoc:
        #reference-doc: 'templates/my-template.docx'
...

breaks pandocomatic (versions > 0.2.0.5)

but

---
pandocomatic_:
    use-template:
        - my-word-template
    pandoc:
        nothing: nothing
        #reference-doc: 'templates/my-template.docx'
...

works.

It seems the parser chokes on a pandoc section with nothing more than a commented out line.

The good news is that knowing this I can review and change my frontmatter as a workaround

Thanks for the complete bug report!

I think I know what causes it: pandocomatic tries to extract YAML metadata from input files using a regular expression and that's the likely culprit for this bug. I'll look into it on Wednesday.

I found the issue: Although I did check if the "pandoc" property was present, I did not take into account this property could then be nil because of the lone comment.

I have created pandocomatic version 0.2.4.2 with a bug-fix.