alibaba/spring-ai-alibaba · error · IllegalArgumentException

Unknown experiment status code: ${code}

Error message

Unknown experiment status code: ${code}

What it means

ExperimentStatus.fromCode(String) looks up the enum constant whose code matches the given string and throws IllegalArgumentException "Unknown experiment status code: X" when no constant matches. This guards the mapping from persisted/transported status codes back to enum values.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/enums/ExperimentStatus.java:52

        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static ExperimentStatus fromCode(String code) {
        for (ExperimentStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown experiment status code: " + code);
    }
} 

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Print/log the offending code and compare with the codes defined in ExperimentStatus (getCode() of each constant).
  2. Fix the data source (DB record, API payload) to use a valid code.
  3. If a new status was added elsewhere, add the matching constant to ExperimentStatus.
  4. Normalize case/trimming before lookup if codes may vary in case.
  5. If legacy codes must be supported, map them to new constants in fromCode.

Example fix

// before
throw new IllegalArgumentException("Unknown experiment status code: " + code);
// after
ExperimentStatus s = Arrays.stream(values()).filter(st -> st.getCode().equalsIgnoreCase(code)).findFirst().orElse(null);
if (s != null) return s;
return ExperimentStatus.PENDING; // or throw with a list of valid codes in the message
Defensive patterns

Strategy: try-catch

Validate before calling

boolean valid = Arrays.stream(ExperimentStatus.values())
    .anyMatch(s -> s.getCode().equals(code));

Try / catch

try { status = ExperimentStatus.fromCode(code); } catch (IllegalArgumentException e) { log.warn("Unknown status '{}', defaulting to PENDING", code); status = ExperimentStatus.PENDING; }

Prevention

When it happens

Trigger: Calling ExperimentStatus.fromCode() with a code not present in the enum's values(), e.g. a typo, an old/renamed code from a persisted DB row, or a status written by a different version of the app.

Common situations: Reading legacy experiment rows whose status codes predate an enum refactor; hand-edited data; API clients sending unrecognized status strings; case mismatch ("RUNNING" vs "running").

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/c40bc3ec21878068. Report an issue: GitHub.