zincsearch/zincsearch · error · errors.Error
invalid_argument
invalid_argument
Error message
user id is required
What it means
GetUser(id) is the lookup function for users by their id. It validates that the id parameter is non-empty and returns an invalid_argument error when it is an empty string, preventing pointless storage lookups. The caller (e.g. CreateUser checking for name collisions) passes a value that ended up empty.
Source
Thrown at pkg/auth/getuser.go:26
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package auth
import (
"github.com/zincsearch/zincsearch/pkg/errors"
"github.com/zincsearch/zincsearch/pkg/meta"
"github.com/zincsearch/zincsearch/pkg/metadata"
)
func GetUser(id string) (*meta.User, bool, error) {
if id == "" {
return nil, false, errors.New(errors.ErrorTypeInvalidArgument, "user id is required")
}
user, err := metadata.User.Get(id)
if err != nil {
return nil, false, err
}
return user, true, nil
}
func SetUser(id string, user meta.User) error {
return metadata.User.Set(id, user)
}
View on GitHub (pinned to dd2f8afd65)
Solutions
- Ensure the user id is set and non-empty before calling GetUser or CreateUser
- Validate request payloads server-side and reject user objects missing an id
- When using CreateUser, pass a non-empty first argument (the id) since it is also used as the login name
Example fix
// before
user, exists, _ := zinc.GetUser(id)
// after
if id == "" {
return errors.New("user id must be provided")
}
user, exists, _ := zinc.GetUser(id) Defensive patterns
Strategy: validation
Validate before calling
if id == "" {
return fmt.Errorf("cannot look up user: id is empty")
} Type guard
func hasUserID(u map[string]any) bool {
id, ok := u["_id"].(string)
return ok && id != ""
} Try / catch
user, exists, err := zinc.GetUser(id)
if err != nil {
if strings.Contains(err.Error(), "user id is required") {
return fmt.Errorf("caller bug: empty user id passed")
}
return err
}
if !exists { /* handle not found */ } Prevention
- Always set _id when creating user documents
- Validate HTTP payloads for the id field before calling auth APIs
- Trim whitespace and reject empty ids at the handler boundary
When it happens
Trigger: Calling zinc.GetUser("") directly, or CreateUser with an empty `_id`/name so that the internal uniqueness check calls GetUser with an empty id.
Common situations: Unmarshaling a user JSON document that lacks the id field; binding an HTTP request body where the id field is absent; concatenating/looking up users by a variable that was never populated.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- ZINC_FIRST_ADMIN_USER and ZINC_FIRST_ADMIN_PASSWORD must be
- invalid_argument
- index ${name} does not exists
- bulk index data format error
- index.name should be not empty
AI-assisted analysis of zincsearch/zincsearch@dd2f8afd65 (2026-09-03).
Data as JSON: /api/errors/8e08347616619129.
Report an issue: GitHub.