kaushalmodi / ox-hugo

A carefully crafted Org exporter back-end for Hugo
https://ox-hugo.scripter.co
GNU General Public License v3.0
867 stars 130 forks source link

org-hugo-export-wim-to-md raises 'Args out of range: "", 0, 1' #655

Closed ymd-h closed 2 years ago

ymd-h commented 2 years ago

Thank you for your great project. I use ox-hugo on CI.

Unfortunately, I encounterd args-out-of-range error with ox-hugo-20220613.516. The file can be exported with ox-hugo-20220330.56 at least (ref).

Example Org File

https://gitlab.com/ymd_h/cpprb/-/blob/0e37e8deef95156c5b0ad8e5bce1577f612e90fa/README.org#L102-L119

Ox-Hugo Debug Information

According to the following debug stack, I feel the error might happen inside org-hugo--get-front-matter when "hugo-audio" is empty string. (Actually, I didn't set any #+HUGO_AUDIO: option manually, but template insertion created empty one, and I haven't modified it.)

https://gitlab.com/ymd_h/cpprb/-/jobs/2598741888#L145

emacs --batch README.org -l site/init.el --eval '(setq debug-on-error t)' --eval '(org-hugo-export-wim-to-md :all-subtrees nil t)'
Debugger entered--Lisp error: (args-out-of-range "" 0 1)
  substring("" 0 1)
  org-hugo--string-unquote("")
  org-hugo--get-front-matter((:export-options (subtree visible-only) :back-end #s(org-export-backend :name hugo :parent blackfriday :transcoders ((code . org-hugo-kbd-tags-maybe) (drawer . org-hugo-drawer) (example-block . org-hugo-example-block) (export-block . org-hugo-export-block) (export-snippet . org-hugo-export-snippet) (headline . org-hugo-heading) (inner-template . org-hugo-inner-template) (inline-src-block . org-hugo-inline-src-block) (keyword . org-hugo-keyword) (link . org-hugo-link) (paragraph . org-hugo-paragraph) (src-block . org-hugo-src-block) (special-block . org-hugo-special-block)) :options ((:with-toc nil "toc" org-hugo-export-with-toc) (:section-numbers nil "num" org-hugo-export-with-section-numbers) (:author "AUTHOR" nil user-full-name newline) (:creator "CREATOR" nil org-hugo-export-creator-string) (:with-smart-quotes nil "'" nil) (:with-special-strings nil "-" nil) (:with-sub-superscript nil "^" ...) (:hugo-with-locale "HUGO_WITH_LOCALE" nil nil) (:hugo-front-matter-format "HUGO_FRONT_MATTER_FORMAT" nil org-hugo-front-matter-format) (:hugo-level-offset "HUGO_LEVEL_OFFSET" nil "1") (:hugo-preserve-filling "HUGO_PRESERVE_FILLING" nil org-hugo-preserve-filling) (:hugo-delete-trailing-ws "HUGO_DELETE_TRAILING_WS" nil org-hugo-delete-trailing-ws) (:hugo-section "HUGO_SECTION" nil org-hugo-section) (:hugo-bundle "HUGO_BUNDLE" nil nil) (:hugo-base-dir "HUGO_BASE_DIR" nil org-hugo-base-dir) (:hugo-goldmark "HUGO_GOLDMARK" nil org-hugo-goldmark) (:hugo-code-fence "HUGO_CODE_FENCE" nil t) (:hugo-use-code-for-kbd "HUGO_USE_CODE_FOR_KBD" nil org-hugo-use-code-for-kbd) (:hugo-prefer-hyphen-in-tags "HUGO_PREFER_HYPHEN_IN_TAGS" nil org-hugo-prefer-hyphen-in-tags) (:hugo-allow-spaces-in-tags "HUGO_ALLOW_SPACES_IN_TAGS" nil org-hugo-allow-spaces-in-tags) (:hugo-auto-set-lastmod "HUGO_AUTO_SET_LASTMOD" nil org-hugo-auto-set-lastmod) (:hugo-custom-front-matter "HUGO_CUSTOM_FRONT_MATTER" nil nil space) (:hugo-blackfriday "HUGO_BLACKFRIDAY" nil nil space) (:hugo-front-matter-key-replace "HUGO_FRONT_MATTER_KEY_REPLACE" nil nil space) (:hugo-date-format "HUGO_DATE_FORMAT" nil org-hugo-date-format) (:hugo-paired-shortcodes "HUGO_PAIRED_SHORTCODES" nil org-hugo-paired-shortcodes space) (:hugo-pandoc-citations "HUGO_PANDOC_CITATIONS" nil nil) (:bibliography "BIBLIOGRAPHY" nil nil newline) (:html-container "HTML_CONTAINER" nil org-hugo-container-element) (:html-container-class "HTML_CONTAINER_CLASS" nil "") (:hugo-aliases "HUGO_ALIASES" nil nil space) (:hugo-audio "HUGO_AUDIO" nil nil) ...) :filters ((:filter-body . org-hugo-body-filter)) :blocks nil :menu (72 "Export to Hugo-compatible Markdo..." (... ... ... ... ... ...))) :translate-alist ((code . org-hugo-kbd-tags-maybe) (drawer . org-hugo-drawer) (example-block . org-hugo-example-block) (export-block . org-hugo-export-block) (export-snippet . org-hugo-export-snippet) (headline . org-hugo-heading) (inner-template . org-hugo-inner-template) (inline-src-block . org-hugo-inline-src-block) (keyword . org-hugo-keyword) (link . org-hugo-link) (paragraph . org-hugo-paragraph) (src-block . org-hugo-src-block) (special-block . org-hugo-special-block) (center-block . org-blackfriday-center-block) (example-block . org-blackfriday-example-block) (fixed-width . org-blackfriday-fixed-width) (footnote-reference . org-blackfriday-footnote-reference) (inner-template . org-blackfriday-inner-template) (italic . org-blackfriday-italic) (item . org-blackfriday-item) (latex-environment . org-blackfriday-latex-environment) (latex-fragment . org-blackfriday-latex-fragment) (line-break . org-html-line-break) (plain-list . org-blackfriday-plain-list) (plain-text . org-blackfriday-plain-text) (quote-block . org-blackfriday-quote-block) (radio-target . org-blackfriday-radio-target) (special-block . org-blackfriday-special-block) (src-block . org-blackfriday-src-block) (strike-through . org-blackfriday-strike-through) (table-cell . org-blackfriday-table-cell) (table-row . org-blackfriday-table-row) ...) :exported-data #<hash-table eq 69/4001 0x1ff99550a9dd> :input-buffer "*Ox-hugo Pre-processed README.or..." :input-file "/builds/ymd_h/cpprb/README.org" :with-toc nil :section-numbers t :author "Hiroyuki Yamada" :creator "Emacs 26.1 (Org mode 9.1.14)" :with-smart-quotes nil :with-special-strings t :with-sub-superscript t :hugo-with-locale "" :hugo-front-matter-format "toml" :hugo-level-offset "1" ...))
  org-hugo-body-filter(#("cpprb requires following s..." 0 5 (:parent (paragraph ... ...)) 6 14 (:parent (paragraph ... ...)) 15 24 (:parent (paragraph ... ...)) 25 34 (:parent (paragraph ... ...)) 35 41 (:parent (paragraph ... ...)) 42 55 (:parent (paragraph ... ...)) 61 66 (:parent (paragraph ... ...)) 67 75 (:parent (paragraph ... ...)) ...) hugo (:export-options (subtree visible-only) :back-end #s(org-export-backend :name hugo :parent blackfriday :transcoders (... ... ... ... ... ... ... ... ... ... ... ... ...) :options (... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) :filters (...) :blocks nil :menu (72 "Export to Hugo-compatible ..." ...)) :translate-alist ((code . org-hugo-kbd-tags-maybe) (drawer . org-hugo-drawer) (example-block . org-hugo-example-block) (export-block . org-hugo-export-block) (export-snippet . org-hugo-export-snippet) (headline . org-hugo-heading) (inner-template . org-hugo-inner-template) (inline-src-block . org-hugo-inline-src-block) (keyword . org-hugo-keyword) (link . org-hugo-link) (paragraph . org-hugo-paragraph) (src-block . org-hugo-src-block) (special-block . org-hugo-special-block) (center-block . org-blackfriday-center-block) (example-block . org-blackfriday-example-block) (fixed-width . org-blackfriday-fixed-width) (footnote-reference . org-blackfriday-footnote-reference) (inner-template . org-blackfriday-inner-template) (italic . org-blackfriday-italic) (item . org-blackfriday-item) (latex-environment . org-blackfriday-latex-environment) (latex-fragment . org-blackfriday-latex-fragment) (line-break . org-html-line-break) (plain-list . org-blackfriday-plain-list) (plain-text . org-blackfriday-plain-text) (quote-block . org-blackfriday-quote-block) ...) :exported-data #<hash-table eq 69/4001 0x1ff99550a9dd> :input-buffer "*Ox-hugo Pre-processed REA..." :input-file "/builds/ymd_h/cpprb/README..." :with-toc nil :section-numbers t :author "Hiroyuki Yamada" :creator "Emacs 26.1 (Org mode 9.1.1..." :with-smart-quotes nil :with-special-strings t :with-sub-superscript t ...))
  org-export-filter-apply-functions((org-hugo-body-filter) #("cpprb requires following s..." 0 5 (:parent (paragraph ... ...)) 6 14 (:parent (paragraph ... ...)) 15 24 (:parent (paragraph ... ...)) 25 34 (:parent (paragraph ... ...)) 35 41 (:parent (paragraph ... ...)) 42 55 (:parent (paragraph ... ...)) 61 66 (:parent (paragraph ... ...)) 67 75 (:parent (paragraph ... ...)) ...) (:export-options (subtree visible-only) :back-end #s(org-export-backend :name hugo :parent blackfriday :transcoders (... ... ... ... ... ... ... ... ... ... ... ... ...) :options (... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) :filters (...) :blocks nil :menu (72 "Export to Hugo-compatible ..." ...)) :translate-alist ((code . org-hugo-kbd-tags-maybe) (drawer . org-hugo-drawer) (example-block . org-hugo-example-block) (export-block . org-hugo-export-block) (export-snippet . org-hugo-export-snippet) (headline . org-hugo-heading) (inner-template . org-hugo-inner-template) (inline-src-block . org-hugo-inline-src-block) (keyword . org-hugo-keyword) (link . org-hugo-link) (paragraph . org-hugo-paragraph) (src-block . org-hugo-src-block) (special-block . org-hugo-special-block) (center-block . org-blackfriday-center-block) (example-block . org-blackfriday-example-block) (fixed-width . org-blackfriday-fixed-width) (footnote-reference . org-blackfriday-footnote-reference) (inner-template . org-blackfriday-inner-template) (italic . org-blackfriday-italic) (item . org-blackfriday-item) (latex-environment . org-blackfriday-latex-environment) (latex-fragment . org-blackfriday-latex-fragment) (line-break . org-html-line-break) (plain-list . org-blackfriday-plain-list) (plain-text . org-blackfriday-plain-text) (quote-block . org-blackfriday-quote-block) ...) :exported-data #<hash-table eq 69/4001 0x1ff99550a9dd> :input-buffer "*Ox-hugo Pre-processed REA..." :input-file "/builds/ymd_h/cpprb/README..." :with-toc nil :section-numbers t :author "Hiroyuki Yamada" :creator "Emacs 26.1 (Org mode 9.1.1..." :with-smart-quotes nil :with-special-strings t :with-sub-superscript t ...))
  org-export-as(hugo :subtreep t nil (:output-file "/builds/ymd_h/cpprb/site/content/installation/_ind..."))
  org-export-to-file(hugo "/builds/ymd_h/cpprb/site/content/installation/_ind..." nil :subtreep t)
  org-hugo-export-to-md(nil :subtreep t)
  org-hugo--export-subtree-to-md(nil t :all-subtrees)
  #f(compiled-function () #<bytecode 0x1ff9954f5fc1>)()
  org-scan-tags(#f(compiled-function () #<bytecode 0x1ff9954f5fc1>) (lambda (todo tags-list level) (progn (setq org-cached-props nil) (or (and (org-string<> (or (org-cached-entry-get nil "EXPORT_FILE_NAME") "") ""))))) nil nil)
  org-map-entries(#f(compiled-function () #<bytecode 0x1ff9954f5fc1>) "EXPORT_FILE_NAME<>\"\"")
  org-hugo-export-wim-to-md(:all-subtrees nil t)
  eval((org-hugo-export-wim-to-md :all-subtrees nil t) t)
  command-line-1(("README.org" "-l" "site/init.el" "--eval" "(setq debug-on-error t)" "--eval" "(org-hugo-export-wim-to-md :all-subtrees nil t)"))
  command-line()
  normal-top-level()

https://github.com/kaushalmodi/ox-hugo/blob/2b46cd602c9692e339833a765ef6fe3acc4fa2ec/ox-hugo.el#L4150

kaushalmodi commented 2 years ago

Thank you for your great project.

Thank you ☺️. You are welcome.

According to the following debug stack,

Thanks for providing the back trace. The issue is here:

https://github.com/kaushalmodi/ox-hugo/blob/2b46cd602c9692e339833a765ef6fe3acc4fa2ec/ox-hugo.el#L4011-L4015

Actually, I didn't set any #+HUGO_AUDIO: option manually, but template insertion created empty one, and I haven't modified it.

You identified the issue correctly. The empty keywords are causing the problem.

The substring retrieval attempt is happening even when the string is of zero length i.e "". This wasn't caught earlier because I don't have empty #+HUGO_..: keywords like you have in your Org file.

If you delete all the empty keyword lines, this error will go away. You shouldn't need to have those empty value keywords in the template anyways.

Let me know if doing that helps you get past this issue. In the meanwhile I'll fix this bug later today.

kaushalmodi commented 2 years ago

You didn't see this issue earlier because the affected code in the backtrace was changed between ox-hugo-20220330.56 and ox-hugo-20220613.516: https://github.com/kaushalmodi/ox-hugo/commit/c24ea792484598ffd2f8e786fadb823d48c8ec12

ymd-h commented 2 years ago

@kaushalmodi Thank you for your quick replay!

By removing empty keywords from the front matter, I could solve this issue. https://gitlab.com/ymd_h/cpprb/-/jobs/2599250225

Thank you for your kind support.

kaushalmodi commented 2 years ago

@ymd-h This issue is now fixed. But feel free to comment here if that's not the case for you.

By removing empty keywords from the front matter, I could solve this issue.

Good to see that nothing else broke in the build :)