puter icon indicating copy to clipboard operation
puter copied to clipboard

Workers 500 Internal Server Error when doing `puter.fs.write` on relative path

Open reynaldichernando opened this issue 3 months ago • 6 comments

https://rey-hello.puter.work

The code

router.get('/', async ({request}) => {
    await me.puter.fs.write("test.txt", "hi");
    return 'Hello World'; // returns a string
});

Result

Image

But having the route absolute at either of these will work

  • /<name>/test.txt
  • ~/test.txt

so i think it's because of the relative path


Another thing, for my original code of having just test.txt i'm not sure where it will be created, but naturally I would expect it to be the same directory from where I have my worker code in

reynaldichernando avatar Oct 08 '25 14:10 reynaldichernando

#1710 will fix the 500 response and give a more appropriate 400 response which will call this an "unresolved relative path" and suggest that the user has to specify an absolute path.

Right now puter.js is responsible for resolving relative paths but that's only a thing for apps (in the case of apps, it's the appdata directory). What would me.puter in a worker have as it's "working directory"? I don't think we've discussed this before. If it's the developers home directory that could get messy - maybe workers need a directory for this.

KernelDeimos avatar Oct 08 '25 20:10 KernelDeimos

Right now puter.js is responsible for resolving relative paths but that's only a thing for apps (in the case of apps, it's the appdata directory).

That makes sense

What would me.puter in a worker have as it's "working directory"?

I think another idea we could explore is the worker current working directory, so it's not necessarily home, so if i create worker in say /username/workers/hello/worker.js, all the files will be under /username/workers/hello/

reynaldichernando avatar Oct 09 '25 04:10 reynaldichernando

I like the idea above, barring security issues we should probably do this for workers

jelveh avatar Oct 09 '25 18:10 jelveh

#1710 will fix the 500 response and give a more appropriate 400 response which will call this an "unresolved relative path" and suggest that the user has to specify an absolute path.

Right now puter.js is responsible for resolving relative paths but that's only a thing for apps (in the case of apps, it's the appdata directory). What would me.puter in a worker have as it's "working directory"? I don't think we've discussed this before. If it's the developers home directory that could get messy - maybe workers need a directory for this.

Since me.puter is godmode by default I guess there is no such thing as a default cwd

ProgrammerIn-wonderland avatar Oct 09 '25 21:10 ProgrammerIn-wonderland

any issue with having the worker's dirname as the path I cprefix to the filename to prevent this from happening?

jelveh avatar Oct 12 '25 16:10 jelveh

there isn't really a worker dirname by default currently. Frontend can specify an app context to run the worker as but the current behavior is god mode so it runs in the root level context, not really as an app at all, it doesn't really have a home

ProgrammerIn-wonderland avatar Oct 16 '25 17:10 ProgrammerIn-wonderland