octobercms/october · error · SystemException

Invalid documentMetadata

Error message

Invalid documentMetadata

What it means

getRequestMetadata() requires the request input 'documentMetadata' to be an array (it carries mtime/path/type metadata for editor commands); anything else — missing, string, null — throws SystemException 'Invalid documentMetadata'. Like the other editor-extension input guards, it signals a malformed internal request rather than an end-user mistake.

Source

Thrown at modules/cms/classes/editorextension/HasExtensionCrud.php:424

        $datasource->forceDeleteModelAtIndex(0, $template);
    }

    /**
     * getThemeDatasource returns a theme datasource object
     */
    protected function getThemeDatasource()
    {
        return $this->getTheme()->getDatasource();
    }

    /**
     * getRequestMetadata
     */
    private function getRequestMetadata()
    {
        $metadata = Request::input('documentMetadata');
        if (!is_array($metadata)) {
            throw new SystemException('Invalid documentMetadata');
        }

        return $metadata;
    }

    /**
     * getRequestExtraData
     */
    private function getRequestExtraData()
    {
        $extraData = Request::input('extraData');
        if (!is_array($extraData)) {
            return [];
        }

        return $extraData;
    }

View on GitHub (pinned to b608633a7e)

Solutions

  1. Send documentMetadata as an array, e.g. {mtime: 1690000000, path: 'index.htm', type: 'page'}
  2. Replay a request captured from the stock editor to learn the expected payload shape
  3. Clear cached assets after upgrading so the matching editor JS is served

Example fix

// before
$.request('onSaveDocument', { data: { documentData: {...} } }); // no metadata

// after
$.request('onSaveDocument', { data: { documentData: {...}, documentMetadata: { mtime: 1690000000, path: 'index.htm', type: 'page' } } });
Defensive patterns

Strategy: type-guard

Validate before calling

if (!is_array($metadata = request()->input('documentMetadata'))) {
    $metadata = ['mtime' => null, 'path' => $path, 'type' => $type]; // or reject the request
}

Type guard

function isDocumentMetadata(m) {
  return m != null && typeof m === 'object' && !Array.isArray(m);
}

Prevention

When it happens

Trigger: Calling an editor-extension command that needs metadata (save/open flows) without documentMetadata in the request, or sending it as a JSON string instead of a parsed array.

Common situations: Custom clients or tests hitting editor endpoints directly; middleware altering request input; stale cached editor assets after a Winter upgrade.

Related errors


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/537e24694c2837ab. Report an issue: GitHub.