gofr-dev/gofr · error

both username and password must be provided

Error message

both username and password must be provided

What it means

errInvalidCredentialsConfig is returned by authenticateCredentials when SurrealDB authentication is attempted without both a username and a password present in the configuration. gofr treats partial credentials as a configuration defect and refuses to authenticate.

Source

Thrown at pkg/gofr/datasource/surrealdb/surrealdb.go:20

import (
	"context"
	"errors"
	"fmt"
	"math"
	"strings"
	"time"

	"github.com/surrealdb/surrealdb.go"
	"github.com/surrealdb/surrealdb.go/pkg/models"
	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/trace"
)

var (
	errNotConnected             = errors.New("not connected to database")
	errNoDatabaseInstance       = errors.New("failed to connect to SurrealDB: no valid database instance")
	errInvalidCredentialsConfig = errors.New("both username and password must be provided")
	errNoRecord                 = errors.New("no record found")
	errNoResult                 = errors.New("no result found in query response")
	errUnexpectedResult         = errors.New("unexpected result type: expected []any")
	errQueryError               = errors.New("query error")
)

const (
	schemeHTTP      = "http"
	schemeHTTPS     = "https"
	schemeWS        = "ws"
	schemeWSS       = "wss"
	schemeMemory    = "memory"
	schemeMem       = "mem"
	schemeSurrealkv = "surrealkv"
	statusOK        = "OK"

	defaultTimeout = 30 * time.Second
)

View on GitHub (pinned to 187eb24962)

Solutions

  1. Set both username and password env/config values (e.g. SURREALDB_USER and SURREALDB_PASS).
  2. Verify the secret containing credentials is actually mounted and non-empty in the container.
  3. Check for env var name typos and that the values aren't blank strings.

Example fix

// before
SURREALDB_USER=root
SURREALDB_PASS=            # empty
// after
SURREALDB_USER=root
SURREALDB_PASS=secret123
Defensive patterns

Strategy: validation

Validate before calling

user, pass := os.Getenv("SURREALDB_USER"), os.Getenv("SURREALDB_PASS")
if user == "" || pass == "" {
    return errors.New("both SURREALDB_USER and SURREALDB_PASS must be set")
}

Prevention

When it happens

Trigger: Connect/authenticate flow where only one of SURREALDB_USER / SURREALDB_PASS (or equivalent config fields) is set, or both are empty while authentication is required.

Common situations: Missing env var in one deployment environment, secret not mounted so the password env is empty, typo in the env var name, or a config struct where only the user field was populated.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/0ec8d75e59319d46. Report an issue: GitHub.