cakephp/cakephp · error · InvalidArgumentException

Cannot format editor URL

Error message

Cannot format editor URL `%s` is not a known editor.

What it means

Debugger::editorUrl() reads the configured 'editor' config and requires it to exist in the registered editors map before it can build a clickable file URL. If the configured editor is unknown (or was never set/registered), it throws InvalidArgumentException.

Solutions

  1. Call Debugger::setEditor() with a valid, registered editor name before editorUrl()
  2. If a custom editor is intended, register it with addEditor() first
  3. Inspect Debugger::getConfig('editor') and correct the value

Example fix

// before
Debugger::setConfig('editor', 'mine');
$url = Debugger::editorUrl('/app/src/Foo.php', 12);
// after
Debugger::setEditor('vscode');
$url = Debugger::editorUrl('/app/src/Foo.php', 12);
Defensive patterns

Strategy: validation

Validate before calling

$editor = Debugger::getConfig('editor'); if (!in_array($editor, array_keys(Debugger::getEditors()), true)) { Debugger::setEditor('phpstorm'); }

Try / catch

try { $url = Debugger::editorUrl($file, $line); } catch (\InvalidArgumentException $e) { $url = $file . ':' . $line; }

Prevention

When it happens

Trigger: Calling Debugger::editorUrl($file, $line) after setConfig('editor', ...) was set to an unregistered name, or with the default editor config removed/invalid.

Common situations: Setting editor via config string without registering a custom editor; serialization/config drift where 'editor' holds a stale name; tests overriding editor config with invalid values.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of cakephp/cakephp@1128eba9b0 (2026-09-12). Data as JSON: /api/errors/23bf4222bb8a7587. Report an issue: GitHub.

Appendix: source

Thrown at src/Error/Debugger.php:237

                $known,
            ));
        }
        $instance->setConfig('editor', $name);
    }

    /**
     * Get a formatted URL for the active editor.
     *
     * @param string $file The file to create a link for.
     * @param int $line The line number to create a link for.
     * @return string The formatted URL.
     */
    public static function editorUrl(string $file, int $line): string
    {
        $instance = static::getInstance();
        $editor = $instance->getConfig('editor');
        if (!isset($instance->editors[$editor])) {
            throw new InvalidArgumentException(sprintf(
                'Cannot format editor URL `%s` is not a known editor.',
                $editor,
            ));
        }

        $editorBasePath = $instance->getConfig('editorBasePath');
        if ($editorBasePath !== null && is_string($editorBasePath)) {
            $file = str_replace(ROOT, $editorBasePath, $file);
        }

        $template = $instance->editors[$editor];
        if (is_string($template)) {
            return str_replace(['{file}', '{line}'], [$file, (string)$line], $template);
        }

        return $template($file, $line);
    }

View on GitHub (pinned to 1128eba9b0)