Tiddlywiki cli crashes upon render command

Hello, everyone!

I am back after a sort-of hiatus from programming and tiddly-ing — it’s nice to be back, and I hope that in the coming months I’ll give a little more back to this community! :sparkles:

At the moment, I am having an issue that relates to another thing I’m trying out. I am trying to run a rendering command

tiddlywiki ~/paogarden --render "[tag[public-eng]]" "[get[slug]addsuffix[.html]]" text/plain $:/core/templates/paogarden.tiddler.html

but it soon fails with

node:internal/errors:540
      throw error;
      ^

TypeError [ERR_INVALID_ARG_TYPE]: The "paths[1]" argument must be of type string. Received undefined
    at Object.resolve (node:path:1128:7)
    at $:/core/modules/commands/render.js:48:24
    at $tw.utils.each ($:/boot/boot.js:146:12)
    at Command.execute ($:/core/modules/commands/render.js:47:13)
    at Commander.executeNextCommand ($:/core/modules/commander.js:107:14)
    at Commander.execute ($:/core/modules/commander.js:64:7)
    at exports.startup ($:/core/modules/startup/commands.js:34:12)
    at $tw.boot.executeNextStartupTask ($:/boot/boot.js:2585:10)
    at $tw.boot.executeNextStartupTask ($:/boot/boot.js:2583:21)
    at $tw.boot.executeNextStartupTask ($:/boot/boot.js:2583:21) {
  code: 'ERR_INVALID_ARG_TYPE'
}

it does render a few files, however, in alphabetic order; and there is one that it will consistently not render and I am not sure why. Below you’ll also find the contents of my tiddlywiki.info file.

    "description": "Basic client-server edition",
    "plugins": [
        "tiddlywiki/tiddlyweb",
        "tiddlywiki/filesystem",
        "tiddlywiki/highlight",
		"tiddlywiki/codemirror"
    ],
    "themes": [
        "tiddlywiki/vanilla",
        "tiddlywiki/snowwhite"
    ],
    "build": {
        "index": [
            "--rendertiddler",
            "$:/plugins/tiddlywiki/tiddlyweb/save/offline",
            "index.html",
            "text/plain"
        ],
        "static": [
            "--rendertiddler",
            "$:/core/templates/static.template.html",
            "static.html",
            "text/plain",
            "--rendertiddler",
            "$:/core/templates/alltiddlers.template.html",
            "alltiddlers.html",
            "text/plain",
            "--rendertiddlers",
            "[!is[system]]",
            "$:/core/templates/static.tiddler.html",
            "static",
            "text/plain",
            "--rendertiddler",
            "$:/core/templates/static.template.css",
            "static/static.css",
            "text/plain"
        ]
    }
}

Any guidance would be tremendously appreciated! I could not find much about the problem from reading the source code.

Thank you in advance!

Hello, everyone!

I managed to solve this after a closer look to the source code (and some AI assistance :grin:). In fact, it was not very difficult to solve; I’ll document the thought process in case anybody comes across this later.

The error message is not very useful, other than providing the information that paths[1] is undefined,

TypeError [ERR_INVALID_ARG_TYPE]: The "paths[1]" argument must be of type string. Received undefined

and filenameFilter came from

filenameFilter = this.params[1] || "[is[tiddler]addsuffix[.html]]",

which would be my [get[slug]addsuffix[.html]]. I had checked and it seemed like all of the posts I was trying to render had the slug field, but I was wrong; a few had slipped through the cracks. So as soon as I got the slug field on all, the problem didn’t appear again.

I am wondering whether it would make sense to have a more informative error message? I understand it is a rather niche error to have, but it was nevertheless caused by improper filter applied to a given tiddler, and that would make it easier to pinpoint the problem. On the other hand, I’m not sure how many other niche problems one would have to cover, nor whether that would be reasonable in such big projects like TiddlyWiki.

Thank you all for your time!

1 Like

Hi @paotsaq thank you for the report, and I’m glad you were able to figure it out.

I’ve pushed a fix for the next release here. Instead of crashing, it now outputs a message “Not rendering “X” because the filename filter returned an empty result”

2 Likes

Hello @jeremyruston! This seems perfect. My only concern is whether this unprotected query happens elsewhere in the code, but I’ll be on the lookout for it.

Thank you very much, again!