{"record":{"id":"bc1109979d79b9c1","repo":"go-gorm/gorm","slug":"empty-slice-found","errorCode":null,"errorMessage":"empty slice found","messagePattern":"empty slice found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":37,"sourceCode":"\tErrUnsupportedRelation = errors.New(\"unsupported relations\")\n\t// ErrPrimaryKeyRequired primary keys required\n\tErrPrimaryKeyRequired = errors.New(\"primary key required\")\n\t// ErrModelValueRequired model value required\n\tErrModelValueRequired = errors.New(\"model value required\")\n\t// ErrModelAccessibleFieldsRequired model accessible fields required\n\tErrModelAccessibleFieldsRequired = errors.New(\"model accessible fields required\")\n\t// ErrSubQueryRequired sub query required\n\tErrSubQueryRequired = errors.New(\"sub query required\")\n\t// ErrInvalidData unsupported data\n\tErrInvalidData = errors.New(\"unsupported data\")\n\t// ErrUnsupportedDriver unsupported driver\n\tErrUnsupportedDriver = errors.New(\"unsupported driver\")\n\t// ErrRegistered registered\n\tErrRegistered = errors.New(\"registered\")\n\t// ErrInvalidField invalid field\n\tErrInvalidField = errors.New(\"invalid field\")\n\t// ErrEmptySlice empty slice found\n\tErrEmptySlice = errors.New(\"empty slice found\")\n\t// ErrDryRunModeUnsupported dry run mode unsupported\n\tErrDryRunModeUnsupported = errors.New(\"dry run mode unsupported\")\n\t// ErrInvalidDB invalid db\n\tErrInvalidDB = errors.New(\"invalid db\")\n\t// ErrInvalidValue invalid value\n\tErrInvalidValue = errors.New(\"invalid value, should be pointer to struct or slice\")\n\t// ErrInvalidValueOfLength invalid values do not match length\n\tErrInvalidValueOfLength = errors.New(\"invalid association values, length doesn't match\")\n\t// ErrPreloadNotAllowed preload is not allowed when count is used\n\tErrPreloadNotAllowed = errors.New(\"preload is not allowed when count is used\")\n\t// ErrDuplicatedKey occurs when there is a unique key constraint violation\n\tErrDuplicatedKey = errors.New(\"duplicated key not allowed\")\n\t// ErrForeignKeyViolated occurs when there is a foreign key constraint violation\n\tErrForeignKeyViolated = errors.New(\"violates foreign key constraint\")\n\t// ErrCheckConstraintViolated occurs when there is a check constraint violation\n\tErrCheckConstraintViolated = errors.New(\"violates check constraint\")\n)\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/go-gorm/gorm/blob/1d6ce99528060be18a42be09aca8d39efcb47f28/errors.go#L19-L55","documentation":"Error \"empty slice found\" thrown in go-gorm/gorm.","triggerScenarios":"Thrown at errors.go:37 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Guard against empty slices before calling Create/Find, e.g. if len(users) == 0 { return }.","Ensure the slice passed to CreateInBatches contains at least one element.","Check that query results are non-empty before passing them to batch operations."],"exampleFix":"Reject empty slices before batch operations: if len(items) == 0 { return nil } ; db.Create(&items)","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1d6ce99528060be18a42be09aca8d39efcb47f28","analyzedAt":"2026-08-15T13:01:23.433Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}