monicahq/monica · error · Exception
The name order must contain at least one variable.
Error message
The name order must contain at least one variable.
What it means
The name_order preference is a template mixing literal text with %-delimited placeholders (%first_name%, %last_name%, %middle_name%, %nickname%, %maiden_name% — see NameHelper). checkNameOrderValidity() first requires at least one '%' character; a template containing no placeholder at all is rejected with this \Exception (rendered as a 500).
Source
Thrown at app/Domains/Settings/ManageUserPreferences/Services/StoreNameOrderPreference.php:53
/**
* Store name order preference for the given user.
*/
public function execute(array $data): User
{
$this->data = $data;
$this->validateRules($data);
$this->checkNameOrderValidity();
$this->updateUser();
return $this->author;
}
private function checkNameOrderValidity(): void
{
// there should be at least one variable in the name order
if (substr_count($this->data['name_order'], '%') < 1) {
throw new \Exception('The name order must contain at least one variable.');
}
if (substr_count($this->data['name_order'], '%') % 2 == 1) {
throw new \Exception('At least one % is missing to have a valid name order.');
}
}
private function updateUser(): void
{
$this->author->name_order = $this->data['name_order'];
$this->author->save();
}
}
View on GitHub (pinned to e08e917341)
Solutions
- Include at least one placeholder pair, e.g. '%first_name% %last_name%'
- Validate client-side before submit: the string must match /%[a-z_]+%/
- Build the value from the known placeholder vocabulary instead of accepting free text
Example fix
// before $data = ['name_order' => 'John Smith']; // no placeholder -> throws // after $data = ['name_order' => '%first_name% %last_name%'];
Defensive patterns
Strategy: validation
Validate before calling
// Validate before calling: require at least one %-delimited placeholder
$nameOrder = $data['name_order'];
if (! preg_match('/%[a-z_]+%/', $nameOrder)) {
throw ValidationException::withMessages([
'name_order' => 'The name order must contain at least one variable like %first_name%.',
]);
} Type guard
function containsNamePlaceholder(string $nameOrder): bool
{
return preg_match('/%[a-z_]+%/', $nameOrder) === 1;
} Try / catch
try {
app(StoreNameOrderPreference::class)->execute($data);
} catch (\Exception $e) {
if (str_contains($e->getMessage(), 'name order')) {
throw ValidationException::withMessages(['name_order' => $e->getMessage()]);
}
throw $e;
} Prevention
- Build the input from a fixed set of placeholder tokens in the UI rather than free text
- Run the /%[a-z_]+%/ client-side check before enabling submit
- Show live preview of the rendered name as the user edits the template
- Add form-request validation so bad templates 422 instead of 500
When it happens
Trigger: Saving the name order preference with a plain literal like 'John Smith' or a template from which every placeholder was removed — zero '%' characters in the submitted name_order string.
Common situations: Users clearing the template and typing their own name, frontends allowing submit without any placeholder selected, or API tests posting free-text strings.
Related errors
- At least one % is missing to have a valid name order.
- Could not get address book data.
- No address book found
- $e->getMessage()
- The user does not belong to the vault's account.
AI-assisted analysis of monicahq/monica@e08e917341 (2026-08-17).
Data as JSON: /api/errors/7b0c2de5dd2391e7.
Report an issue: GitHub.