gotify/server · error

could not get user: %s

Error message

could not get user: %s

What it means

During CreateUser the handler resolves the acting user via auth.TryGetUserID and a.DB.GetUserByID to decide authorization (admin vs non-admin vs anonymous). If the user ID from the auth context cannot be fetched from the database, the request is aborted with a 500 and "could not get user: <err>". This signals a stale/invalid session identity or a database failure.

Source

Thrown at api/user.go:215

			ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to prepare password: %s", err))
			return
		}
		internal := &model.User{
			Name:  user.Name,
			Admin: user.Admin,
			Pass:  pw,
		}
		existingUser, err := a.DB.GetUserByName(internal.Name)
		if success := successOrAbort(ctx, 500, err); !success {
			return
		}

		var requestedBy *model.User
		uid := auth.TryGetUserID(ctx)
		if uid != nil {
			requestedBy, err = a.DB.GetUserByID(*uid)
			if err != nil {
				ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("could not get user: %s", err))
				return
			}
		}

		if requestedBy == nil || !requestedBy.Admin {
			status := http.StatusUnauthorized
			if requestedBy != nil {
				status = http.StatusForbidden
			}
			if !a.Registration {
				ctx.AbortWithError(status, errors.New("you are not allowed to access this api"))
				return
			}
			if internal.Admin {
				ctx.AbortWithError(status, errors.New("you are not allowed to create an admin user"))
				return
			}
		}

View on GitHub (pinned to 14bfc25627)

Solutions

  1. Re-authenticate to obtain a fresh token bound to an existing user.
  2. Verify the referenced user still exists in the database (check the users table for the ID).
  3. Check DB connectivity/logs for the underlying error appended after 'could not get user:'.
  4. If migrating/restoring data, regenerate or reconcile sessions and foreign keys.
Defensive patterns

Strategy: try-catch

Try / catch

if resp.StatusCode == http.StatusInternalServerError && strings.Contains(body, "could not get user") {
    // identity no longer resolvable: clear session and re-authenticate
    session.Invalidate()
    return ErrReauthRequired
}

Prevention

When it happens

Trigger: Any authenticated CreateUser request whose token/session user ID no longer resolves in the DB (user deleted after token issuance, DB read error, wrong DB backend), or where GetUserByID returns an error.

Common situations: Tokens issued before a database restore/migration; user removed while a session was still valid; database connectivity problems or a misconfigured DB driver.

Related errors


AI-assisted analysis of gotify/server@14bfc25627 (2026-09-05). Data as JSON: /api/errors/f7b489e209b4b03c. Report an issue: GitHub.