iflytek/astron-agent · error · IllegalArgumentException

Timeout must be between 1-300 seconds

Error message

Timeout must be between 1-300 seconds

What it means

validateTextGenerationParams requires the timeout 'seconds' to be strictly between 1 and 300 inclusive; otherwise it throws IllegalArgumentException('Timeout must be between 1-300 seconds'). This bounds how long generateText will block on latch.await for the WebSocket response.

Solutions

  1. Clamp the timeout at the call site: Math.max(1, Math.min(300, configuredSeconds))
  2. Fix unit confusion if the config value is in milliseconds (divide by 1000)
  3. Provide a sane default (e.g. 60s) when the timeout config is missing or zero

Example fix

// before
int seconds = (int) timeoutConfig.getValue(); // 30000 (ms)
botAIServiceClient.generateText(prompt, domain, seconds);
// after
int seconds = Math.max(1, Math.min(300, (int) (timeoutConfig.getValue() / 1000)));
botAIServiceClient.generateText(prompt, domain, seconds);
Defensive patterns

Strategy: validation

Validate before calling

if (seconds <= 0 || seconds > 300) { seconds = Math.max(1, Math.min(300, seconds)); }

Try / catch

try { return client.generateText(q, domain, seconds); } catch (IllegalArgumentException e) { log.warn("Bad timeout: {}", e.getMessage()); return client.generateText(q, domain, 60); }

Prevention

When it happens

Trigger: generateText(question, domain, 0), negative seconds, or seconds > 300 — a caller computing the timeout from a bad config value or passing a millisecond value where seconds is expected.

Common situations: Configuration storing timeout in milliseconds (e.g. 30000) passed directly as seconds, a default of 0 meaning 'unset', or an attempt to allow very long generations beyond the 300s cap.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/bed250afff8c1981. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/BotAIServiceClient.java:248

            if (e instanceof BusinessException) {
                throw e;
            }
            throw new BusinessException(ResponseEnum.SYSTEM_ERROR);
        }
    }

    /**
     * Validate text generation parameters
     */
    private void validateTextGenerationParams(String question, String domain, int seconds) {
        if (question == null || question.trim().isEmpty()) {
            throw new IllegalArgumentException("Generation prompt cannot be empty");
        }
        if (domain == null || domain.trim().isEmpty()) {
            throw new IllegalArgumentException("Model domain cannot be empty");
        }
        if (seconds <= 0 || seconds > 300) {
            throw new IllegalArgumentException("Timeout must be between 1-300 seconds");
        }
    }

    /**
     * Convert AI service error code to corresponding ResponseEnum
     *
     * @param errorCode Error code returned by AI service
     * @return Corresponding ResponseEnum
     */
    private ResponseEnum convertTextErrorCodeToResponseEnum(Integer errorCode) {
        if (errorCode == null) {
            return ResponseEnum.SYSTEM_ERROR;
        }

        ResponseEnum responseEnum = TEXT_ERROR_CODE_MAP.get(errorCode);
        if (responseEnum == null) {
            log.warn("Unknown AI text service error code: {}", errorCode);
            return ResponseEnum.SYSTEM_ERROR;

View on GitHub (pinned to 5e758547a8)