flarum/framework · error · ValidationException

custom_less

Error message

custom_less

What it means

In ValidateCustomLess::whenSettingsSaving, after re-writing settings in a trial compile, the code builds CSS assets for the default and each locale. If less.php raises Less_Exception_Parser during compilation, it is re-thrown as ValidationException keyed on 'custom_less' with the parser's message — meaning the saved custom LESS contains syntax errors.

Solutions

  1. Read the parser message shown in the admin panel — it includes the line/character of the syntax error — and fix the LESS at that location.
  2. Validate balanced braces and LESS-compatible syntax (convert SCSS-specific syntax like $variables to LESS @variables).
  3. Revert to the previously working custom LESS, then re-apply changes incrementally to find the offending snippet.

Example fix

// before
.button { color: $primary; }

// after (LESS syntax, not SCSS)
.button { color: @primary; }
Defensive patterns

Strategy: try-catch

Validate before calling

// quick local check with less.php before saving
$parser = new Less_Parser();
try { $parser->parse($customLess); } catch (Less_Exception_Parser $e) {
  // show $e->getMessage() (has line/column) before submitting
}

Try / catch

try {
    $this->settings->save(['custom_less' => $less]);
} catch (ValidationException $e) {
    $msg = $e->errors()['custom_less'] ?? 'Invalid LESS';
}

Prevention

When it happens

Trigger: Saving custom LESS that fails to compile: unbalanced braces, invalid LESS syntax, bad variable usage, or any construct the Less parser rejects while running makeCss()/makeLocaleCss() commits.

Common situations: Admins pasting SCSS (not LESS) into custom_less; copy/paste truncation leaving unclosed braces; LESS referencing undefined mixins/variables from a removed extension.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of flarum/framework@4b939f6853 (2026-09-15). Data as JSON: /api/errors/9dcdde56ff6459aa. Report an issue: GitHub.

Appendix: source

Thrown at framework/core/src/Forum/ValidateCustomLess.php:106

                return new OverrideSettingsRepository($settings, $event->settings);
            }
        );

        $assetsDir = $this->assets->getAssetsDir();

        $adapter = new InMemoryFilesystemAdapter();
        $this->assets->setAssetsDir(new FilesystemAdapter(new Filesystem($adapter), $adapter));

        $this->settings->delete('custom_less_error');

        try {
            $this->assets->makeCss()->commit();

            foreach ($this->locales->getLocales() as $locale => $name) {
                $this->assets->makeLocaleCss($locale)->commit();
            }
        } catch (Less_Exception_Parser $e) {
            throw new ValidationException(['custom_less' => $e->getMessage()]);
        }

        if (! empty($this->settings->get('custom_less_error'))) {
            throw new ValidationException(['custom_less' => $this->settings->get('custom_less_error')]);
        }

        $this->assets->setAssetsDir($assetsDir);
        $this->container->instance(SettingsRepositoryInterface::class, $settings);
    }

    public function whenSettingsSaved(Saved $event): void
    {
        if (! isset($event->settings['custom_less']) && ! $this->hasDirtyCustomLessSettings($event)) {
            return;
        }

        // Flag rather than delete, so the stylesheets already referenced by
        // served pages keep resolving until their replacements exist. The

View on GitHub (pinned to 4b939f6853)