twibiral / obsidian-execute-code

Obsidian Plugin to execute code in a note.
MIT License
994 stars 61 forks source link

[BUG] No such file or directory when running code in 1.11.1 (reverting back to 1.11.0 removes the error) #347

Closed tlwt closed 1 month ago

tlwt commented 2 months ago

Describe the bug Running any script in obsidian with version 1.1.1 returns the following error message with varying tmp file names: [BUG] bash: /var/folders/mc/tr50w1s94cb27zw9_zfpcn_40000gn/Ttemp_1715179358918.sh:. Reverting back to 1.11.0 makes script runnable again.

Software Version Mac OS X 14.4.1 (23E224), Obsidian Version 1.5.12 (Installer 1.4.13), Plugin Execute Code 1.11.1 running on MacBook Pro, 13-inch, M1, 2020

To Reproduce Steps to reproduce the behavior:

  1. Reproduce above setup. Create a new note: with the following content:
    ```run-shell
    ls 

Error message: 

ls bash: /var/folders/mc/tr50w1s94cb27zw9_zfpcn_40000gn/Ttemp_1715179637189.sh: No such file or directory


2. Revert back to 1.11.0 and run the same code - no problem

**Expected behavior**
The command should be executed unter 1.11.1

**Screenshots**
![Bildschirmfoto 2024-05-08 um 16 48 31](https://github.com/twibiral/obsidian-execute-code/assets/8267086/4eb910f6-840c-406d-bf1b-51926164887a)

**Additional context**
Add any other context about the problem here.
tlwt commented 2 months ago

I checked the change logs and they seem really minor. I have been trying to integrate PHP myself into the plugin (#263) and that error kept popping up. Could it be that Obsidian caches somewhere my own builds even when deleting the folder manually? I have not seen any similar problem reports.

sbhal commented 2 months ago

I have experienced similar issue after upgrading to 1.11.1. Reverting back to 1.11.0 resolves the issue. Macbook pro 2019 (Intel) with Macos Sonoma 14.4.1 . Obsidian Version 1.5.12 (Installer 1.4.13).

nfiles commented 2 months ago

The issue is caused by a hard-coded Windows file separator. I pushed a PR that resolves this issue on my 2019 Mac Pro. :)

There are other hard-coded file separators in src, which makes me think this should also be tested on a Windows/WSL environment.

$ grep -rni '\\\\' src
src/settings/SettingsTab.ts:257:                path = path.replace(/\\/g, '/');
src/transforms/Magic.ts:44:     source = source.replace(VAULT_PATH_REGEX, `"${vaultPath.replace(/\\/g, "/")}"`);
src/transforms/Magic.ts:45:     source = source.replace(VAULT_URL_REGEX, `"${Platform.resourcePathPrefix + vaultPath.replace(/\\/g, "/")}"`);
src/transforms/Magic.ts:46:     source = source.replace(VAULT_REGEX, `"${Platform.resourcePathPrefix + vaultPath.replace(/\\/g, "/")}"`);
src/transforms/Magic.ts:60:     source = source.replace(CURRENT_NOTE_PATH_REGEX, `"${notePath.replace(/\\/g, "/")}"`);
src/transforms/Magic.ts:61:     source = source.replace(CURRENT_NOTE_URL_REGEX, `"${Platform.resourcePathPrefix + notePath.replace(/\\/g, "/")}"`);
src/transforms/Magic.ts:62:     source = source.replace(CURRENT_NOTE_REGEX, `"${Platform.resourcePathPrefix + notePath.replace(/\\/g, "/")}"`);
src/transforms/Magic.ts:144:            const tempFile = `${os.tmpdir()}/temp_${Date.now()}.png`.replace(/\\/g, "/");
src/transforms/Magic.ts:166:            const image = buildMagicShowImage(imagePath.replace(/\\/g, "\\\\"), width, height, alignment);
src/transforms/Magic.ts:202:            const image = buildMagicShowImage(imagePath.replace(/\\/g, "\\\\"), width, height, alignment);
src/transforms/Magic.ts:249:            const tempFile = `${os.tmpdir()}/temp_${Date.now()}.png`.replace(/\\/g, "/");
src/transforms/Magic.ts:261:            const tempFile = `${os.tmpdir()}/temp_${Date.now()}.png`.replace(/\\/g, "/");
src/executors/ClingExecutor.ts:52:                      return data.replace(new RegExp(`temp_${fileId}\\(\\)`, "g"), "main()");
src/Outputter.ts:115:           text = text.replace(/\x1b\\[;\d]*m/g, "")
src/Outputter.ts:132:           text = text.replace(/\x1b\\[;\d]*m/g, "")
nfiles commented 2 months ago

I tested the above PR on my windows 10/WSL machine and can confirm that it works for

twibiral commented 1 month ago

Fixed with new release version 1.12.0