{"record":{"id":"b2c4f59c1dd7ec69","repo":"alibaba/nacos","slug":"agent-labelsobjectrequired","errorCode":null,"errorMessage":"agent.labelsObjectRequired","messagePattern":"agent\\.labelsObjectRequired","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"console-ui-next/src/pages/agentDetail/index.tsx","lineNumber":289,"sourceCode":"    try {\n      await agentApi.deleteDraft({\n        namespaceId,\n        agentName,\n        version: currentVersion.version,\n      });\n      toast.success(t('agent.deleteDraftSuccess'));\n      setSelectedVersion('');\n      await loadOverview();\n    } finally {\n      setActionLoading(false);\n    }\n  };\n\n  const updateLabels = async () => {\n    try {\n      const parsed = JSON.parse(labelsText);\n      if (parsed === null || Array.isArray(parsed) || typeof parsed !== 'object') {\n        throw new Error(t('agent.labelsObjectRequired'));\n      }\n      if ('latest' in parsed) {\n        throw new Error(t('agent.latestLabelManaged'));\n      }\n      await agentApi.updateLabels({\n        namespaceId,\n        agentName,\n        labels: JSON.stringify(parsed),\n      });\n      toast.success(t('agent.updateSuccess'));\n      await loadOverview();\n    } catch (error) {\n      if (error instanceof SyntaxError || (error instanceof Error && !('response' in error))) {\n        toast.error(error instanceof SyntaxError ? t('agent.jsonFormatError') : error.message);\n      }\n    }\n  };\n","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/console-ui-next/src/pages/agentDetail/index.tsx#L271-L307","documentation":"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.","triggerScenarios":"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\"}.","commonSituations":"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.","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."],"exampleFix":"// before\n{\"prod\", \"v2\"}   // or [\"prod\",\"v2\"]\n\n// after\n{\"env\":\"prod\",\"version\":\"v2\"}","handlingStrategy":"validation","validationCode":"function parseLabels(text) {\n  const parsed = JSON.parse(text);\n  if (parsed === null || Array.isArray(parsed) || typeof parsed !== 'object') {\n    throw new Error('Labels must be a JSON object');\n  }\n  return parsed;\n}","typeGuard":"function isLabelsObject(v: unknown): v is Record<string, string> {\n  return v !== null && !Array.isArray(v) && typeof v === 'object';\n}","tryCatchPattern":"try { await updateLabels(); } catch (e) {\n  if (e instanceof SyntaxError) { toast.error('Invalid JSON'); }\n  else if (/labelsObjectRequired/.test(e.message)) { toast.error('Labels must be a key-value object'); }\n}","preventionTips":["Default textarea to {}","Show a placeholder example","Validate object shape before submit"],"tags":["validation","labels","json","agent"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}