500 internal Server Error when accessing files in '/media/plugins' Kirby 4

Hi,

i just made my plugin/template compatible with Kirby 4 but noticed some occasionally 500 internal Server Errors when accessing the ‘media/plugins’ files. Sometimes i realod the page and my favicon/appletouchicon, javascript, CSS or fonts are not loading because they run into 500. After refreshing the page, this error is gone usually but happens some refreshes later again.

Any Ideas?

thats the json response i get, i am also wondering about the URL difference.

A 500 Internal Server Error is always reported in the server log with more details.

I read that out and get a similar error:
Whoops\\Exception\\ErrorException: rmdir(C:\\xampp\\htdocs\\khepri-template-base\\media\\plugins\\khepri-design\\khepri-base\\assets): No such file or directory in C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php:549

My Plugin Structure looks like that:

Good evening @texnixe ,
do you have any idea, what could be the issue here?
I double checked, if the directory can be written, cause thats what the Dir.php checks when throwing the error. I tried it our on localhost via xampp and on a webserver.

The weird thing is, that it seems like right-issues but they only oncure happen on about 2/3 page refreshes. Sometimes everything is fine, but after a refresh, the favicon is missing for e.g

[Mon Sep 11 00:23:17.126753 2023] [php:notice] [pid 15688:tid 1856] [client 127.0.0.1:63329] Exception: The directory "C:\\xampp\\htdocs\\khepri-template-base/media/plugins/khepri-design/khepri-base/assets/img" cannot be created in C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php:412\nStack trace:\n#0 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php(407): Kirby\\Filesystem\\Dir::make('C:\\\\xampp\\\\htdocs...', true)\n#1 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\F.php(328): Kirby\\Filesystem\\Dir::make('C:\\\\xampp\\\\htdocs...', true)\n#2 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\PluginAssets.php(64): Kirby\\Filesystem\\F::link('C:\\\\xampp\\\\htdocs...', 'C:\\\\xampp\\\\htdocs...', 'symlink')\n#3 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\config\\routes.php(72): Kirby\\Cms\\PluginAssets::resolve('khepri-design/k...', 'assets/img/plac...')\n#4 [internal function]: Kirby\\Http\\Route->{closure}('khepri-design', 'khepri-base', 'assets/img/plac...')\n#5 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Http\\Router.php(122): Closure->call(Object(Kirby\\Http\\Route), 'khepri-design', 'khepri-base', 'assets/img/plac...')\n#6 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\App.php(337): Kirby\\Http\\Router->call('media/plugins/k...', 'GET')\n#7 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\App.php(1190): Kirby\\Cms\\App->call('media/plugins/k...', 'GET')\n#8 C:\\xampp\\htdocs\\khepri-template-base\\index.php(5): Kirby\\Cms\\App->render()\n#9 {main}, referer: http://localhost/khepri-template-base/
[Mon Sep 11 00:23:17.169282 2023] [php:notice] [pid 15688:tid 1820] [client 127.0.0.1:63326] Whoops\\Exception\\ErrorException: scandir(C:\\xampp\\htdocs\\khepri-template-base\\media\\plugins\\khepri-design\\khepri-base\\assets\\img): Das System kann den angegebenen Pfad nicht find (code: 3) in C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php:535\nStack trace:\n#0 [internal function]: Whoops\\Run->handleError(2, 'scandir(C:\\\\xamp...', 'C:\\\\xampp\\\\htdocs...', 535)\n#1 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php(535): scandir('C:\\\\xampp\\\\htdocs...')\n#2 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php(543): Kirby\\Filesystem\\Dir::remove('C:\\\\xampp\\\\htdocs...')\n#3 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\PluginAssets.php(39): Kirby\\Filesystem\\Dir::remove('C:\\\\xampp\\\\htdocs...')\n#4 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\PluginAssets.php(59): Kirby\\Cms\\PluginAssets::clean('khepri-design/k...')\n#5 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\config\\routes.php(72): Kirby\\Cms\\PluginAssets::resolve('khepri-design/k...', 'assets/webfonts...')\n#6 [internal function]: Kirby\\Http\\Route->{closure}('khepri-design', 'khepri-base', 'assets/webfonts...')\n#7 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Http\\Router.php(122): Closure->call(Object(Kirby\\Http\\Route), 'khepri-design', 'khepri-base', 'assets/webfonts...')\n#8 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\App.php(337): Kirby\\Http\\Router->call('media/plugins/k...', 'GET')\n#9 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\App.php(1190): Kirby\\Cms\\App->call('media/plugins/k...', 'GET')\n#10 C:\\xampp\\htdocs\\khepri-template-base\\index.php(5): Kirby\\Cms\\App->render()\n#11 {main}, referer: http://localhost/khepri-template-base/media/plugins/khepri-design/khepri-base/assets/css/min/all.min.css
[Mon Sep 11 00:23:17.350283 2023] [php:notice] [pid 15688:tid 1856] [client 127.0.0.1:63331] Whoops\\Exception\\ErrorException: scandir(C:\\xampp\\htdocs\\khepri-template-base\\media\\plugins\\khepri-design\\khepri-base\\assets\\webfonts): Das System kann den angegebenen Pfad nicht find (code: 3) in C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php:510\nStack trace:\n#0 [internal function]: Whoops\\Run->handleError(2, 'scandir(C:\\\\xamp...', 'C:\\\\xampp\\\\htdocs...', 510)\n#1 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php(510): scandir('C:\\\\xampp\\\\htdocs...')\n#2 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php(156): Kirby\\Filesystem\\Dir::read('C:\\\\xampp\\\\htdocs...', Array)\n#3 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php(172): Kirby\\Filesystem\\Dir::index('C:\\\\xampp\\\\htdocs...', true, Array, 'assets/webfonts')\n#4 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php(172): Kirby\\Filesystem\\Dir::index('C:\\\\xampp\\\\htdocs...', true, Array, 'assets')\n#5 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\PluginAssets.php(30): Kirby\\Filesystem\\Dir::index('C:\\\\xampp\\\\htdocs...', true)\n#6 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\PluginAssets.php(59): Kirby\\Cms\\PluginAssets::clean('khepri-design/k...')\n#7 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\config\\routes.php(72): Kirby\\Cms\\PluginAssets::resolve('khepri-design/k...', 'assets/img/plac...')\n#8 [internal function]: Kirby\\Http\\Route->{closure}('khepri-design', 'khepri-base', 'assets/img/plac...')\n#9 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Http\\Router.php(122): Closure->call(Object(Kirby\\Http\\Route), 'khepri-design', 'khepri-base', 'assets/img/plac...')\n#10 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\App.php(337): Kirby\\Http\\Router->call('media/plugins/k...', 'GET')\n#11 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\App.php(1190): Kirby\\Cms\\App->call('media/plugins/k...', 'GET')\n#12 C:\\xampp\\htdocs\\khepri-template-base\\index.php(5): Kirby\\Cms\\App->render()\n#13 {main}, referer: http://localhost/khepri-template-base/
[Mon Sep 11 00:23:17.366282 2023] [php:notice] [pid 15688:tid 1896] [client 127.0.0.1:63330] Whoops\\Exception\\ErrorException: rmdir(C:\\xampp\\htdocs\\khepri-template-base\\media\\plugins\\khepri-design\\khepri-base\\assets\\img): No such file or directory in C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php:549\nStack trace:\n#0 [internal function]: Whoops\\Run->handleError(2, 'rmdir(C:\\\\xampp\\\\...', 'C:\\\\xampp\\\\htdocs...', 549)\n#1 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php(549): rmdir('C:\\\\xampp\\\\htdocs...')\n#2 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Filesystem\\Dir.php(543): Kirby\\Filesystem\\Dir::remove('C:\\\\xampp\\\\htdocs...')\n#3 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\PluginAssets.php(39): Kirby\\Filesystem\\Dir::remove('C:\\\\xampp\\\\htdocs...')\n#4 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\PluginAssets.php(59): Kirby\\Cms\\PluginAssets::clean('khepri-design/k...')\n#5 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\config\\routes.php(72): Kirby\\Cms\\PluginAssets::resolve('khepri-design/k...', 'assets/webfonts...')\n#6 [internal function]: Kirby\\Http\\Route->{closure}('khepri-design', 'khepri-base', 'assets/webfonts...')\n#7 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Http\\Router.php(122): Closure->call(Object(Kirby\\Http\\Route), 'khepri-design', 'khepri-base', 'assets/webfonts...')\n#8 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\App.php(337): Kirby\\Http\\Router->call('media/plugins/k...', 'GET')\n#9 C:\\xampp\\htdocs\\khepri-template-base\\kirby\\src\\Cms\\App.php(1190): Kirby\\Cms\\App->call('media/plugins/k...', 'GET')\n#10 C:\\xampp\\htdocs\\khepri-template-base\\index.php(5): Kirby\\Cms\\App->render()\n#11 {main}, referer: http://localhost/khepri-template-base/media/plugins/khepri-design/khepri-base/assets/css/min/all.min.css

So you didn’t have that issue before you updated to Kirby 4. Have you made any changes other than replacing the kirby folder?

If you set up a simple plugin with assets in a fresh Kirby 4 starterkit (i.e. Starterkit with kirby folder replaced with new beta kirby folder), do you get the same issue?

The only thing i change is how to include my files cause i noticed, instead of 'media/plugins/khepri-design/khepri-base/img/placeholder/footer-bg.png' i have to mention the ‘assets’ folder since kirby 4 in the Path: “media/plugins/khepri-design/khepri-base/assets/img/placeholder/footer-bg.png” This should be correct, because images etc are found correctly:

But they are not loaded caus a 500error, which tells me, that a media folder could not been removed correctly cause of missing permissions. But i double checked, that the folder is fully accessable:

With a sample plugin in a fresh installation kirby 4, i can embed a image from the media folder with no problems

Unfortunately, you posted your code as image…

but to load the background image with url('http://...)is definitely wrong, should beurl(‘media/plugins…’)`.

Hey, many thanks for your reply.
i fixed your mentioned “url()” call but that is not what causes the problem here. In my other code-sections i am using “url()” or src=“” correct. For e.G a image on my homepage:

<img alt="Hintergrundbild Desktop" class="d-none d-lg-block" src="media/plugins/khepri-design/khepri-base/assets/img/placeholder/entry-background.png">

After every 5 to 6 page reloads, this image is not loaded (500 / Serverside) with the following error:

status	"error"
exception	"Whoops\\Exception\\ErrorException"
code	2
message	"rmdir(C:\\xampp\\htdocs\\khepri-template-base\\media\\plugins\\khepri-design\\khepri-base\\assets): No such file or directory"
details	null
file	"/khepri-template-base/kirby/src/Filesystem/Dir.php"
line	549

I also inspected the file Dir.php and this error should appear when there are missing permissions for deleting files/folders. The error is incomprehensible to me, cause it seems to come up randomly. Sometimes its my main js file, sometime images or fonts.

Hm, maybe it has to do with the assets folder now having to be added to the path (there is already an issue on GitHub for that).

I keep wondering though, why it happens so regularly and why it’s trying to remove the folder ever so often, which seems weird.

Ahh okay can you pass me the github link for that?

Yeah its super strange, i really do not have any idea what causes this, but i think the call of the file in the code (html, css etc.) should not matter, cause it looks like the issue is directly related to the media folder.

Good evening @texnixe
i didn’t find the issue on GitHub, do you remember the title or maybe hava a link?
I would like to check it there are any news ore if the error is my fault and i have to take an action.

Would be awesome :smiley:

This, but with 404 errors, not 500:

Hey thank you again. This didnt fix my issue.
I spend some more time and spotted that PluginAssets::clean in src/Cms/PluginAssets.php has been adjusted a month ago. This causes the Issue for me.

I had to adjust this line to fix it for me:
$root = $media . '/' . $file;
to:
$root = $media . '/assets/' . $file;

I am still confused how this issue could occur irregular and it seems that Fonts were more often effected. Also it may have to do something with my folder structure, but because of the irregularity of this issue nothing makes sence to me haha.

This is my assets structure:

Hey @texnixe :slight_smile:
Sry for disturbing but can you see any conclusing corresponding to my last Message?

Even tho its working now for me, changing a Kirby file is of course not a real Solution.

I Hope you have a great weakend!

Have you tried with the latest beta?

If that doesn’t work, maybe report an issue. Keep in mind that Kirby 4 is still in early beta