{"record":{"id":"ab57cebd1292acff","repo":"Tencent/WeKnora","slug":"model-id-cannot-be-empty","errorCode":null,"errorMessage":"model ID cannot be empty","messagePattern":"model ID cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/model.go","lineNumber":164,"sourceCode":"\t\t} else {\n\t\t\tlogger.Infof(newCtx, \"Model download completed successfully: %s\", model.Name)\n\t\t\tmodel.Status = types.ModelStatusActive\n\t\t}\n\t\tlogger.Infof(newCtx, \"Updating model status to: %s\", model.Status)\n\t\ts.repo.Update(newCtx, model)\n\t}()\n\n\tlogger.Infof(ctx, \"Model creation initiated successfully: %s\", model.ID)\n\treturn nil\n}\n\n// GetModelByID retrieves a model by its ID\n// Returns an error if the model is not found or is in a non-active state\nfunc (s *modelService) GetModelByID(ctx context.Context, id string) (*types.Model, error) {\n\t// Check if ID is empty\n\tif id == \"\" {\n\t\tlogger.Error(ctx, \"Model ID is empty\")\n\t\treturn nil, errors.New(\"model ID cannot be empty\")\n\t}\n\n\ttenantID := types.MustTenantIDFromContext(ctx)\n\n\t// Fetch model from repository\n\tmodel, err := s.repo.GetByID(ctx, tenantID, id)\n\tif err != nil {\n\t\tlogger.ErrorWithFields(ctx, err, map[string]interface{}{\n\t\t\t\"model_id\":  id,\n\t\t\t\"tenant_id\": tenantID,\n\t\t})\n\t\treturn nil, err\n\t}\n\n\t// Check if model exists\n\tif model == nil {\n\t\tlogger.Error(ctx, \"Model not found\")\n\t\treturn nil, ErrModelNotFound","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/model.go#L146-L182","documentation":"GetModelByID validates that the caller passed a non-empty model ID before hitting the repository. When the ID string is empty it logs 'Model ID is empty' and returns errors.New(\"model ID cannot be empty\") immediately, avoiding a pointless repo lookup that would otherwise fail or behave ambiguously. It is a fail-fast precondition check on a required request parameter.","triggerScenarios":"Calling GetModelByID (directly or via GetEmbeddingModel/GetRerankModel) with an empty string as id — typically from an unbound request path/query parameter, a zero-value struct field, or a missing config entry for a model ID.","commonSituations":"HTTP handler binds an optional modelId query/path param and forwards '' as-is; YAML/env config omits the embedding or rerank model ID; a JSON payload omits the field so it unmarshals to the zero value ''; a caller builds the ID by string concatenation over missing data.","solutions":["Ensure the caller (HTTP handler or config loader) validates and rejects empty model IDs before calling GetModelByID/GetEmbeddingModel/GetRerankModel.","Log or echo the failing request so the source of the empty ID (query param, body field, config key) can be identified.","Make the model ID required at the API boundary (e.g. Gin binding tag binding:\"required\") so empty values are rejected with a 400 before reaching the service.","Check config files/env for the specific model ID key (e.g. embedding model ID) and set it to the actual model identifier."],"exampleFix":"// before\nmodel, err := modelService.GetEmbeddingModel(ctx, c.Query(\"modelId\"))\n// after\nmodelId := c.Query(\"modelId\")\nif modelId == \"\" {\n    c.JSON(http.StatusBadRequest, gin.H{\"error\": \"modelId is required\"})\n    return\n}\nmodel, err := modelService.GetEmbeddingModel(ctx, modelId)","handlingStrategy":"validation","validationCode":"if modelID == \"\" {\n    return nil, fmt.Errorf(\"model ID is required\")\n}\nmodel, err := svc.GetModelByID(ctx, modelID)","typeGuard":"func hasModelID(s string) bool { return strings.TrimSpace(s) != \"\" }","tryCatchPattern":"model, err := svc.GetModelByID(ctx, modelID)\nif err != nil {\n    if err.Error() == \"model ID cannot be empty\" {\n        return nil, fmt.Errorf(\"invalid request: modelId is required\")\n    }\n    return nil, err\n}","preventionTips":["Mark modelId as required in HTTP binding (e.g. binding:\"required\") so empty values fail with 400 at the boundary.","Validate config-loaded model IDs at startup, not at request time.","Never pass optional/zero-value strings straight into service calls.","Add unit tests for empty-ID inputs on model service calls."],"tags":["go","validation","empty-argument","model-service"],"backgroundTag":"empty-required-parameter","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}