iflytek/astron-agent · error · BusinessException

RESPONSE_FAILED

RESPONSE_FAILED

Error message

Related enumeration class not found

What it means

DBTableEnvEnum.getByCode(code) linearly searches the enum's values for a matching Integer code and returns its string value. When no constant matches, it throws BusinessException(ResponseEnum.RESPONSE_FAILED, "Related enumeration class not found"). This is a lookup-miss guard translating a raw DB integer code into a human-readable environment name.

Solutions

  1. Log the offending code value and add a matching DBTableEnvEnum constant for it.
  2. Verify the code stored in the DB table is valid; fix bad rows with an UPDATE if they are corrupt.
  3. If the code comes from user input, validate it against the enum's known codes before calling getByCode.
  4. As hardening, return an Optional or default value instead of throwing for unknown codes if unmapped values are tolerable.

Example fix

// before
throw new BusinessException(ResponseEnum.RESPONSE_FAILED, "Related enumeration class not found");

// after
DBTableEnvEnum matched = Arrays.stream(values())
        .filter(e -> Objects.equals(e.getCode(), code)).findFirst().orElse(null);
if (matched == null) {
    log.warn("Unknown DBTableEnvEnum code={}", code);
    return "UNKNOWN";
}
return matched.getValue();
Defensive patterns

Strategy: validation

Validate before calling

final Set<Integer> known = Arrays.stream(DBTableEnvEnum.values())
        .map(DBTableEnvEnum::getCode).collect(Collectors.toSet());
if (!known.contains(code)) {
    log.warn("Skipping unknown env code={}", code);
}

Type guard

boolean isKnownEnvCode(Integer code) {
    return Arrays.stream(DBTableEnvEnum.values())
            .anyMatch(e -> Objects.equals(e.getCode(), code));
}

Try / catch

try {
    String env = DBTableEnvEnum.getByCode(code);
} catch (BusinessException e) {
    log.warn("Unmapped env code={}, using default", code);
    String env = DEFAULT_ENV;
}

Prevention

When it happens

Trigger: Calling DBTableEnvEnum.getByCode with an Integer that is not one of the enum's defined codes (e.g. a new environment value inserted into a DB table without adding the corresponding enum constant).

Common situations: A database migration or another service wrote a new env code the enum does not know; a typo'd or null-shifted code passed from a form; enum updated in one module but the calling code uses stale codes after a version upgrade.

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 iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/6b77f9e5172a4304. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/entity/enumVo/DBTableEnvEnum.java:39

        this.code = code;
        this.value = value;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public static String getByCode(Integer code) {
        for (DBTableEnvEnum envEnum : DBTableEnvEnum.values()) {
            if (Objects.equals(envEnum.getCode(), code)) {
                return envEnum.getValue();
            }
        }
        throw new BusinessException(ResponseEnum.RESPONSE_FAILED, "Related enumeration class not found");
    }
}

View on GitHub (pinned to 5e758547a8)