alibaba/nacos · error · Error
agent.labelsObjectRequired
Error message
agent.labelsObjectRequired
What it means
Thrown by updateLabels in the agent detail page when the labels text parses as valid JSON but is not a plain object — i.e. it is null, an array, or a primitive. The check uses `parsed === null || Array.isArray(parsed) || typeof parsed !== 'object'`. The message is i18n-keyed (`agent.labelsObjectRequired`) and rendered to the user as a toast.
Source
Thrown at console-ui-next/src/pages/agentDetail/index.tsx:289
try {
await agentApi.deleteDraft({
namespaceId,
agentName,
version: currentVersion.version,
});
toast.success(t('agent.deleteDraftSuccess'));
setSelectedVersion('');
await loadOverview();
} finally {
setActionLoading(false);
}
};
const updateLabels = async () => {
try {
const parsed = JSON.parse(labelsText);
if (parsed === null || Array.isArray(parsed) || typeof parsed !== 'object') {
throw new Error(t('agent.labelsObjectRequired'));
}
if ('latest' in parsed) {
throw new Error(t('agent.latestLabelManaged'));
}
await agentApi.updateLabels({
namespaceId,
agentName,
labels: JSON.stringify(parsed),
});
toast.success(t('agent.updateSuccess'));
await loadOverview();
} catch (error) {
if (error instanceof SyntaxError || (error instanceof Error && !('response' in error))) {
toast.error(error instanceof SyntaxError ? t('agent.jsonFormatError') : error.message);
}
}
};
View on GitHub (pinned to 9b989acdf1)
Solutions
- Enter labels as a JSON object of key-value pairs, e.g. {"env":"prod","tier":"frontend"}.
- If you intended a tag list, confirm whether the backend supports an array format; if not, map each tag to a key.
- Provide the user a hint/placeholder showing the expected object shape.
Example fix
// before
{"prod", "v2"} // or ["prod","v2"]
// after
{"env":"prod","version":"v2"} Defensive patterns
Strategy: validation
Validate before calling
function parseLabels(text) {
const parsed = JSON.parse(text);
if (parsed === null || Array.isArray(parsed) || typeof parsed !== 'object') {
throw new Error('Labels must be a JSON object');
}
return parsed;
} Type guard
function isLabelsObject(v: unknown): v is Record<string, string> {
return v !== null && !Array.isArray(v) && typeof v === 'object';
} Try / catch
try { await updateLabels(); } catch (e) {
if (e instanceof SyntaxError) { toast.error('Invalid JSON'); }
else if (/labelsObjectRequired/.test(e.message)) { toast.error('Labels must be a key-value object'); }
} Prevention
- Default textarea to {}
- Show a placeholder example
- Validate object shape before submit
When it happens
Trigger: User enters labels as a JSON array `["prod", "v2"]`, a bare string, the literal `null`, or a JSON number. The labels feature expects a key-value map such as {"env":"prod"}.
Common situations: User confuses the labels field with a tag list (expecting an array). User clears the textarea and it defaults to "null". Copy-pasting a JSON array from another system.
Related errors
- Labels must be a JSON object
- The latest label is managed by the server
- ${name} must be valid JSON
- ${name} must be a JSON object
- callInterfaces must be a non-empty JSON array
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/b2c4f59c1dd7ec69.
Report an issue: GitHub.