{"record":{"id":"3e8e8c2170fda1b6","repo":"alibaba/spring-ai-alibaba","slug":"unknown-agent-status-code","errorCode":null,"errorMessage":"Unknown agent status code: ","messagePattern":"Unknown agent status code: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/runtime/enums/agent/AgentStatus.java","lineNumber":54,"sourceCode":"\tERROR(\"error\");\n\n\tprivate final String code;\n\n\tAgentStatus(String code) {\n\t\tthis.code = code;\n\t}\n\n\tpublic String getCode() {\n\t\treturn code;\n\t}\n\n\tpublic static AgentStatus fromCode(String code) {\n\t\tfor (AgentStatus status : values()) {\n\t\t\tif (status.getCode().equals(code)) {\n\t\t\t\treturn status;\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalArgumentException(\"Unknown agent status code: \" + code);\n\t}\n\n}\n","sourceCodeStart":36,"sourceCodeEnd":58,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/runtime/enums/agent/AgentStatus.java#L36-L58","documentation":"AgentStatus.fromCode maps a string status code to the AgentStatus enum by scanning values(); if no constant matches, it throws IllegalArgumentException. It is a strict code-to-enum translation guard for agent status values.","triggerScenarios":"Calling AgentStatus.fromCode(code) with any string that does not exactly equal one of the enum constants' getCode() values (null, typo, different casing, or a status code from an older/newer schema).","commonSituations":"Deserializing agent status from a database or API response that stores legacy or unknown codes; case mismatch ('DRAFT' vs 'draft'); a new status added in one version but read by an older client.","solutions":["Log and inspect the offending code string and compare with the valid values() codes.","Fix the stored/serialized value to a valid AgentStatus code.","Handle case/whitespace differences (code.trim().toUpperCase()) before calling fromCode.","Use a lenient lookup (return null or Optional) if unknown codes should be tolerated."],"exampleFix":"// before\nAgentStatus status = AgentStatus.fromCode(rawStatus);\n// after\nAgentStatus status = Arrays.stream(AgentStatus.values())\n    .filter(s -> s.getCode().equalsIgnoreCase(rawStatus == null ? \"\" : rawStatus.trim()))\n    .findFirst()\n    .orElseThrow(() -> new IllegalArgumentException(\"Unknown agent status code: \" + rawStatus));","handlingStrategy":"validation","validationCode":"// Java\nboolean valid = Arrays.stream(AgentStatus.values()).anyMatch(s -> s.getCode().equals(code));\nif (!valid) { log.warn(\"invalid agent status code: {}\", code); return AgentStatus.getDefault(); }","typeGuard":"static Optional<AgentStatus> fromCodeOrNull(String code) {\n    return Arrays.stream(AgentStatus.values()).filter(s -> s.getCode().equals(code)).findFirst();\n}","tryCatchPattern":"try { return AgentStatus.fromCode(code); } catch (IllegalArgumentException e) { log.warn(\"unknown agent status code: {}\", code); return AgentStatus.getDefault(); }","preventionTips":["Never persist raw status strings without validating against enum codes at write time.","Normalize casing/trimming before lookup.","Write a migration when enum constants are renamed or removed.","Prefer lenient Optional-based lookups at ingestion boundaries."],"tags":["enum","agent","illegal-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}