alibaba/spring-ai-alibaba · error · RuntimeException

删除评估器失败

Error message

删除评估器失败

What it means

Thrown by EvaluatorServiceImpl.deleteById when evaluatorMapper.deleteById(id) returns 0 rows affected, meaning no evaluator with the given ID exists in the database (or it was already deleted). It is a generic RuntimeException wrapping a 'no rows deleted' outcome rather than a typed not-found exception.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/EvaluatorServiceImpl.java:150

        int result = evaluatorMapper.update(evaluatorDO);
        if (result > 0) {
            log.info("评估器更新成功: {}", request.getId());
            // 重新查询获取最新数据
            return Evaluator.fromDO(evaluatorMapper.selectById(request.getId()));
        } else {
            throw new RuntimeException("更新评估器失败");
        }
    }

    @Override
    public void deleteById(Long id) {
        log.info("删除评估器: {}", id);

        int result = evaluatorMapper.deleteById(id);
        if (result > 0) {
            log.info("评估器删除成功: {}", id);
        } else {
            throw new RuntimeException("删除评估器失败");
        }
    }

    @Override
    public EvaluatorDebugResult debug(EvaluatorTestRequest request) {
        log.info("调试评估器: {}", request);

        EvaluatorDebugResult result = evaluatorTest(request);

        return result;
    }


    /**
     * 调试模型调用
     */
    public EvaluatorDebugResult evaluatorTest(EvaluatorTestRequest request) {
        ChatSession session = chatSessionService.createEvaluatorSession(request.getPrompt(), request.getVariables(), request.getModelConfig());

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Verify the evaluator ID exists (evaluatorMapper.selectById) before deleting and return a typed 404 if absent
  2. Check result==0 and throw a domain exception like EvaluatorNotFoundException so the controller maps it to 404 instead of 500
  3. Confirm the client is pointed at the environment where the evaluator actually exists
  4. Change deleteById to return the affected count so callers can treat 0 as idempotent success

Example fix

// before
if (result > 0) {
    log.info("评估器删除成功: {}", id);
} else {
    throw new RuntimeException("删除评估器失败");
}
// after
EvaluatorDO existing = evaluatorMapper.selectById(id);
if (existing == null) {
    throw new EvaluatorNotFoundException(id); // mapped to 404
}
evaluatorMapper.deleteById(id);
Defensive patterns

Strategy: validation

Validate before calling

if (id == null || id <= 0) throw new IllegalArgumentException("evaluator id required");
if (evaluatorService.getById(id) == null) throw new EvaluatorNotFoundException(id);

Type guard

boolean evaluatorExists(Long id) { return id != null && id > 0 && evaluatorService.getById(id) != null; }

Try / catch

try { evaluatorService.deleteById(id); } catch (RuntimeException e) { /* map to 404 */ }

Prevention

When it happens

Trigger: Calling DELETE /evaluator/{id} (or service.deleteById) with an ID that does not exist, an already-deleted evaluator, or an ID belonging to another tenant/database.

Common situations: Stale UI state deleting an evaluator removed elsewhere; double-clicking a delete button so the second call hits an already-deleted row; passing a string/truncated ID; wrong database profile (dev vs prod) so the row never existed there.

Related errors


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