TiddlyWiki5 icon indicating copy to clipboard operation
TiddlyWiki5 copied to clipboard

Add NODE_DEV_PATH_STACKTRACE env var to show tiddler filepath instead for single tiddler files

Open Arlen22 opened this issue 11 months ago • 9 comments

Single tiddler files (like javascript files) will use the filepath on disk instead of the tiddler name, allowing the stack trace to be properly clickable (assuming your code editor supports that).

Error: test
    at exports.startup (/home/.../plugins/tiddlywiki/multiwikiserver/modules/startup.js:39:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This doesn't work for files in the boot folder because they have //# sourceURL=$:/boot/..., but it does work for files in core.

Other than being extremely useful, I don't know what the ramifications of this are.

Arlen22 avatar Jan 09 '25 22:01 Arlen22

Confirmed: Arlen22 has already signed the Contributor License Agreement (see contributing.md)

github-actions[bot] avatar Jan 09 '25 22:01 github-actions[bot]

Deploy Preview for tiddlywiki-previews ready!

Name Link
Latest commit 6c3a235ad8663b51875212c2adb79c9c40e9c6fc
Latest deploy log https://app.netlify.com/sites/tiddlywiki-previews/deploys/678061722b1ccf0008f0517a
Deploy Preview https://deploy-preview-8889--tiddlywiki-previews.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Jan 09 '25 22:01 netlify[bot]

Someone needs to check if it changes anything about how the browser handles paths and make sure that the filepath field isn't commonly used for something else. I'm assuming not in Javascript module tiddlers.

It should affect the server edition. If you run the server edition with the env var set, stack traces should include the physical module path as well. I've never seen a good way to use this in the browser, but it would be crazy useful if there was some kind of way to click on a link in your browser and it would take you back to that line in your code editor.

Can someone please figure out whether we can do this with boot.js? I don't know why it has to have a source url set. Perhaps moving the sourceUrl to the rendering tiddler would be a good idea.

Arlen22 avatar Jan 09 '25 22:01 Arlen22

In the browser every module gets a sourceURL info set by TW core. I think it's used to by the debug-tab to show the "file structure" on the left.

The code can be found at: https://github.com/TiddlyWiki/TiddlyWiki5/blob/4478f445a595f5405d7bd3b29744f836f306b453/boot/boot.js#L633

image

pmario avatar Jan 09 '25 23:01 pmario

I am not sure, if we add package-lock.json to a PR. IMO it should be removed. It will be rebuilt by the node build system anyway.

pmario avatar Jan 09 '25 23:01 pmario

@Arlen22 -- Where do you set NODE_DEV_PATH_STACKTRACE and what should it contain. I can not find any useful info about this variable at nodejs.org

pmario avatar Jan 09 '25 23:01 pmario

@pmario

I am not sure, if we add package-lock.json to a PR. IMO it should be removed. It will be rebuilt by the node build system anyway.

Oops, thanks.

Where do you set NODE_DEV_PATH_STACKTRACE and what should it contain. I can not find any useful info about this variable at nodejs.org

It's just whatever we want to make it. I'm sure you or others here can suggest more appropriate names than that. It definitely shouldn't be found on nodejs.org.

When you enable the flag, it adds the 'filepath' field to tiddlers loaded from the file system, so that if they happen to be a module or other runnable code, the filepath can be used in the sourceUrl instead of the tiddler name.

This works because the other line I changed was in $tw.modules.execute, which checks for the filepath field. If it sees the filepath field it will use that instead of the title. This happens whether the flag is enabled or not, so anyone can use it to customize the filepath that is set in sourceUrl.

If you're using the npm run dev command (which runs the dev script in tiddlywiki's package.json file), you would just add the variable in front of it like so. The value is irrelevant, as the code I'm adding simply tests for truthiness.

NODE_DEV_PATH_STACKTRACE=whatever npm run dev

We could also call it TIDDLER_FILEPATH_STACKTRACE or TW_MODULE_FILEPATH. It just needs to be something that we aren't likely to see in the wild.

Arlen22 avatar Jan 10 '25 00:01 Arlen22

In the browser every module gets a sourceURL info set by TW core. I think it's used to by the debug-tab to show the "file structure" on the left.

The code can be found at:

https://github.com/TiddlyWiki/TiddlyWiki5/blob/4478f445a595f5405d7bd3b29744f836f306b453/boot/boot.js#L633

Yes. I believe so. The only exception is the boot folder, since those are rendered right into the HTML file. As such they do not get eval'ed by that line of code. The sourceUrl for those is set in the last line of the source file itself. That affects both node and browser stack traces, but if someone is desperate they can just remove that line since they're probably working on the file anyway.

Arlen22 avatar Jan 10 '25 00:01 Arlen22

@Jermolene ... I think this would be a good improvement for debugability.

pmario avatar Dec 10 '25 18:12 pmario

change this to not use a field and instead use a hashmap of plugin and title to retrieve the file path.

Arlen22 avatar Dec 17 '25 15:12 Arlen22