{"record":{"id":"3edbb54bc9d269ec","repo":"OtterMind/Chat2DB","slug":"model-is-required","errorCode":null,"errorMessage":"model is required","messagePattern":"model is required","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/ai/AiModelConfigServiceImpl.java","lineNumber":361,"sourceCode":"        }\n        if (provider == AiProviderEnum.CLAUDE) {\n            runtimeModel.setApiKey(defaultValue(trimToNull(runtimeModel.getApiKey()), trimToNull(System.getenv(\"ANTHROPIC_API_KEY\"))));\n            runtimeModel.setBaseUrl(defaultValue(trimToNull(runtimeModel.getBaseUrl()), trimToNull(System.getenv(\"ANTHROPIC_BASE_URL\"))));\n            return;\n        }\n        if (provider == AiProviderEnum.GEMINI) {\n            runtimeModel.setProjectId(defaultValue(trimToNull(runtimeModel.getProjectId()), trimToNull(System.getenv(\"GOOGLE_CLOUD_PROJECT\"))));\n            runtimeModel.setLocation(defaultValue(trimToNull(runtimeModel.getLocation()), trimToNull(System.getenv(\"GOOGLE_CLOUD_LOCATION\"))));\n            runtimeModel.setLocation(defaultValue(runtimeModel.getLocation(), DEFAULT_GEMINI_LOCATION));\n        }\n    }\n\n    private void validateRuntimeModel(AiRuntimeModel runtimeModel) {\n        if (Objects.isNull(runtimeModel.getProvider())) {\n            throw new IllegalArgumentException(\"provider is required\");\n        }\n        if (StringUtils.isBlank(runtimeModel.getModel())) {\n            throw new IllegalArgumentException(\"model is required\");\n        }\n        AiProviderEnum provider = AiProviderEnum.from(runtimeModel.getProvider());\n        if (provider == null) {\n            throw new IllegalArgumentException(\"Unsupported provider: \" + runtimeModel.getProvider());\n        }\n        if (provider == AiProviderEnum.OPENAI || provider == AiProviderEnum.CLAUDE) {\n            return;\n        }\n        if (provider == AiProviderEnum.GEMINI) {\n        }\n    }\n\n\n    private synchronized void loadFromDisk() {\n        if (!Files.exists(storagePath)) {\n            return;\n        }\n        try {","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/ai/AiModelConfigServiceImpl.java#L343-L379","documentation":"Thrown as IllegalArgumentException('model is required') by AiModelConfigServiceImpl.validateRuntimeModel when runtimeModel.getModel() is blank. Like error 56 it is a raw IllegalArgumentException (not i18n-handled). It fires after the provider check passes but before the provider enum lookup.","triggerScenarios":"The resolved AiRuntimeModel has a null/blank model string. Reachable when both the request and the base config omitted model, or a saved config has a null model field, and validateRuntimeModel is then called.","commonSituations":"A model config saved with provider+apiKey but no model identifier; a request that sends provider only expecting the model to come from somewhere it did not; programmatic AiRuntimeModel construction skipping setModel.","solutions":["Set a concrete model id (e.g. 'gpt-4o', 'claude-3-5-sonnet') on the saved config or the resolve request.","Validate that the model field is non-blank before persisting an AiModelConfig.","Guard resolveRuntimeModel to throw a BusinessException describing the missing model before validateRuntimeModel."],"exampleFix":"// before\nresolve.setProvider(\"OPENAI\"); resolve.setApiKey(key); // model blank\n\n// after\nresolve.setProvider(\"OPENAI\");\nresolve.setModel(\"gpt-4o\");\nresolve.setApiKey(key);","handlingStrategy":"validation","validationCode":"AiRuntimeModel m = /* built */;\nif (StringUtils.isBlank(m.getModel())) {\n    throw new IllegalArgumentException(\"model is required before validate\");\n}","typeGuard":"static boolean hasModel(AiRuntimeModel m) {\n    return m != null && !StringUtils.isBlank(m.getModel());\n}","tryCatchPattern":"try {\n    service.validateRuntimeModel(m);\n} catch (IllegalArgumentException e) {\n    if (\"model is required\".equals(e.getMessage())) {\n        return ResponseEntity.badRequest().body(\"set a concrete model id\");\n    }\n    throw e;\n}","preventionTips":["Always set a concrete model id on configs and resolve requests.","Validate the model field before persisting a config.","Note these are raw IllegalArgumentExceptions, not i18n BusinessException."],"tags":["ai","model-config","validation","illegal-argument"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}