crater-invoice-inc/crater · error · Exception
Can not create a unique slug
Error message
Can not create a unique slug
What it means
The slug helper clean_slug throws after exhausting its 10 suffix attempts (_1 through _10): every candidate slug already exists for the model, typically because the same base slug was saved many times (e.g. repeated items named identically), so no unique slug can be derived.
Solutions
- Wrap the model save in try-catch and surface a 'please choose a different name' validation error
- Increase the loop bound or switch to a random-suffix/timestamp fallback instead of a fixed 1-10 range
- Use a unique index plus retry logic so the DB remains the source of truth for uniqueness
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at app/Space/helpers.php:179 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of crater-invoice-inc/crater@05d5ce26fd (2026-09-13).
Data as JSON: /api/errors/0fe203b767e27d26.
Report an issue: GitHub.
Appendix: source
Thrown at app/Space/helpers.php:179
// Get any that could possibly be related.
// This cuts the queries down by doing it once.
$allSlugs = getRelatedSlugs($model, $slug, $id);
// If we haven't used it before then we are all good.
if (! $allSlugs->contains('slug', $slug)) {
return $slug;
}
// Just append numbers like a savage until we find not used.
for ($i = 1; $i <= 10; $i++) {
$newSlug = $slug.'_'.$i;
if (! $allSlugs->contains('slug', $newSlug)) {
return $newSlug;
}
}
throw new \Exception('Can not create a unique slug');
}
function getRelatedSlugs($type, $slug, $id = 0)
{
return CustomField::select('slug')->where('slug', 'like', $slug.'%')
->where('model_type', $type)
->where('id', '<>', $id)
->get();
}
function respondJson($error, $message)
{
return response()->json([
'error' => $error,
'message' => $message
], 422);
}
View on GitHub (pinned to 05d5ce26fd)