{"record":{"id":"b2070ee75297cec1","repo":"alibaba/spring-ai-alibaba","slug":"unknown-agent-type-code","errorCode":null,"errorMessage":"Unknown agent type code: ","messagePattern":"Unknown agent type 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/AgentType.java","lineNumber":64,"sourceCode":"\tprivate final String code;\n\n\tAgentType(String code) {\n\t\tthis.code = code;\n\t}\n\n\t@JsonValue\n\tpublic String getCode() {\n\t\treturn code;\n\t}\n\n\t@JsonCreator\n\tpublic static AgentType fromCode(String code) {\n\t\tfor (AgentType type : values()) {\n\t\t\tif (type.getCode().equals(code)) {\n\t\t\t\treturn type;\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalArgumentException(\"Unknown agent type code: \" + code);\n\t}\n\n}\n","sourceCodeStart":46,"sourceCodeEnd":68,"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/AgentType.java#L46-L68","documentation":"AgentType.fromCode maps a string type code to the AgentType enum by scanning values(); if nothing matches it throws IllegalArgumentException. It enforces that only known agent type codes are accepted.","triggerScenarios":"Calling AgentType.fromCode(code) with a string not matching any enum constant's getCode() — e.g. a misspelled type, wrong casing, or a type code written by a newer/older schema version.","commonSituations":"Persisting agent type as a raw string in DB/API payloads and reading it back after a rename or upgrade; frontend sending a type label instead of the canonical code.","solutions":["Print valid codes (Arrays.toString(AgentType.values())) and correct the input to one of them.","Normalize input (trim/case) before the lookup.","Migrate stored data containing stale type codes to current enum codes.","Fall back to a default type or Optional-based lookup if unknown types are expected."],"exampleFix":"// before\nAgentType type = AgentType.fromCode(dto.getType());\n// after\nAgentType type = Optional.ofNullable(AgentType.fromCodeOrNull(dto.getType()))\n    .orElseThrow(() -> new IllegalArgumentException(\"Unsupported agent type: \" + dto.getType()));","handlingStrategy":"validation","validationCode":"// Java\nboolean valid = Arrays.stream(AgentType.values()).anyMatch(t -> t.getCode().equals(typeCode));\nif (!valid) throw new IllegalArgumentException(\"Unsupported agent type: \" + typeCode);","typeGuard":"static Optional<AgentType> fromCodeOrNull(String code) {\n    return Arrays.stream(AgentType.values()).filter(t -> t.getCode().equals(code)).findFirst();\n}","tryCatchPattern":"try { return AgentType.fromCode(typeCode); } catch (IllegalArgumentException e) { log.warn(\"unknown agent type code: {}\", typeCode); return AgentType.defaultType(); }","preventionTips":["Expose only canonical enum codes through your API layer (validate DTOs against enum values).","Normalize case/whitespace before fromCode.","Run data migrations when type codes change across versions.","Add unit tests covering every valid code round-trips through fromCode."],"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"}