Tencent/WeKnora · error
model ID cannot be empty
Error message
model ID cannot be empty
What it means
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.
Source
Thrown at internal/application/service/model.go:164
} else {
logger.Infof(newCtx, "Model download completed successfully: %s", model.Name)
model.Status = types.ModelStatusActive
}
logger.Infof(newCtx, "Updating model status to: %s", model.Status)
s.repo.Update(newCtx, model)
}()
logger.Infof(ctx, "Model creation initiated successfully: %s", model.ID)
return nil
}
// GetModelByID retrieves a model by its ID
// Returns an error if the model is not found or is in a non-active state
func (s *modelService) GetModelByID(ctx context.Context, id string) (*types.Model, error) {
// Check if ID is empty
if id == "" {
logger.Error(ctx, "Model ID is empty")
return nil, errors.New("model ID cannot be empty")
}
tenantID := types.MustTenantIDFromContext(ctx)
// Fetch model from repository
model, err := s.repo.GetByID(ctx, tenantID, id)
if err != nil {
logger.ErrorWithFields(ctx, err, map[string]interface{}{
"model_id": id,
"tenant_id": tenantID,
})
return nil, err
}
// Check if model exists
if model == nil {
logger.Error(ctx, "Model not found")
return nil, ErrModelNotFoundView on GitHub (pinned to 988cbb0330)
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.
Example fix
// before
model, err := modelService.GetEmbeddingModel(ctx, c.Query("modelId"))
// after
modelId := c.Query("modelId")
if modelId == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "modelId is required"})
return
}
model, err := modelService.GetEmbeddingModel(ctx, modelId) Defensive patterns
Strategy: validation
Validate before calling
if modelID == "" {
return nil, fmt.Errorf("model ID is required")
}
model, err := svc.GetModelByID(ctx, modelID) Type guard
func hasModelID(s string) bool { return strings.TrimSpace(s) != "" } Try / catch
model, err := svc.GetModelByID(ctx, modelID)
if err != nil {
if err.Error() == "model ID cannot be empty" {
return nil, fmt.Errorf("invalid request: modelId is required")
}
return nil, err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- unknown credential field:
- member_limit must be >= 0
- cannot request upgrade to same or lower role
- E2B timeout must be at least one second
- invalid sandbox type
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/ab57cebd1292acff.
Report an issue: GitHub.