Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API debug exception error only returns filename (not file path) when DOCUMENT_ROOT differs from site folder #3267

Closed
neildaniels opened this issue Apr 26, 2021 · 1 comment · Fixed by #3268
Labels
type: enhancement ✨ Suggests an enhancement; improves Kirby
Milestone

Comments

@neildaniels
Copy link
Contributor

Describe the bug
In situations where an installation's $_SERVER['DOCUMENT_ROOT'] is set to a secluded folder that is separate from the Kirby installation (and site folder), API exceptions do not return a helpful file path.

To Reproduce
Steps to reproduce the behavior:

  1. Set document root to something like /var/www/html/website/public
  2. Have a plugin in a folder like /var/www/html/website/site/plugins/example-plugin/index.php
  3. Enable debug mode.
  4. Do something in a hook that would throw an exception.

Expected behavior
The JSON API error would say a helpful file path where the error occurred. Instead, you only get the filename.

Actual

{
    "status": "error",
    "message": "Kirby\\Cms\\Site::TheStreamable\\ExamplePlugin\\{closure}(): Argument #1 ($foo) must be of type Object, string given",
    "code": 500,
    "exception": "TypeError",
    "key": null,
    "file": "index.php",
    "line": 122,
    "details": [],
    "route": "pages/([a-zA-Z0-9\\.\\-_%= \\+\\@\\(\\)]+)"
}

Expected

{
    "status": "error",
    "message": "Kirby\\Cms\\Site::TheStreamable\\ExamplePlugin\\{closure}(): Argument #1 ($foo) must be of type Object, string given",
    "code": 500,
    "exception": "TypeError",
    "key": null,
    "file": "/var/www/html/website/site/plugins/example-plugin/index.php",
    "line": 122,
    "details": [],
    "route": "pages/([a-zA-Z0-9\\.\\-_%= \\+\\@\\(\\)]+)"
}

(The expected file path could be truly relative, with something like ../site/plugins/example-plugin/index.php, but I don't really care much either way.)

Kirby Version
3.5.3

Additional context
Relavant Kirby line:

'file' => F::relativepath($e->getFile(), $_SERVER['DOCUMENT_ROOT'] ?? null),

It seems that F:: relativepath() handles the scenario that $file is not a descendant of $in by just returning the filename, which seems like an odd choice to me.

kirby/src/Toolkit/F.php

Lines 646 to 661 in 38afb2d

public static function relativepath(string $file, string $in = null): string
{
if (empty($in) === true) {
return basename($file);
}
// windows
$file = str_replace('\\', '/', $file);
$in = str_replace('\\', '/', $in);
if (Str::contains($file, $in) === false) {
return basename($file);
}
return Str::after($file, $in);
}

@lukasbestle
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement ✨ Suggests an enhancement; improves Kirby
Projects
None yet
2 participants