dgraph-io/dgraph · error
connection string cannot be empty
Error message
connection string cannot be empty
What it means
newClient rejects an empty connection string before attempting any gRPC dial. The import client requires a Dgraph endpoint connection string (e.g. localhost:9080 or a dgo Open string) and cannot proceed without one.
Source
Thrown at dgraph/cmd/dgraphimport/import_client.go:31
"math"
"os"
"path/filepath"
"strings"
"time"
"github.com/dgraph-io/badger/v4"
"github.com/dgraph-io/dgo/v250"
"github.com/dgraph-io/dgo/v250/protos/api"
"github.com/dgraph-io/ristretto/v2/z"
"github.com/golang/glog"
"golang.org/x/sync/errgroup"
)
// newClient creates a new import client with the specified endpoint and gRPC options.
func newClient(connectionString string) (api.DgraphClient, error) {
if connectionString == "" {
return nil, fmt.Errorf("connection string cannot be empty")
}
dg, err := dgo.Open(connectionString)
if err != nil {
return nil, fmt.Errorf("failed to connect to endpoint [%s]: %w", connectionString, err)
}
glog.Infof("[import] Successfully connected to Dgraph endpoint: %s", connectionString)
return dg.GetAPIClients()[0], nil
}
func Import(ctx context.Context, connectionString string, bulkOutDir string) error {
if bulkOutDir == "" {
return fmt.Errorf("bulk output directory cannot be empty")
}
dg, err := newClient(connectionString)
if err != nil {View on GitHub (pinned to 759e242be6)
Solutions
- Provide a non-empty connection string to Import, e.g. "localhost:9080".
- Check where the value originates (flag/env/config) and validate it before calling Import.
- Default the endpoint in your tooling to the standard Alpha gRPC address localhost:9080.
- If dgo TLS options are needed, include them in the connection string rather than leaving it empty.
Example fix
// before
err := dgraphimport.Import(ctx, os.Getenv("DGRAPH_ADDR"), outDir) // env unset → ""
// after
addr := os.Getenv("DGRAPH_ADDR")
if addr == "" { addr = "localhost:9080" }
err := dgraphimport.Import(ctx, addr, outDir) Defensive patterns
Strategy: validation
Validate before calling
if err := validateAddr(addr); err != nil { return err }
func validateAddr(addr string) error {
if strings.TrimSpace(addr) == "" {
return errors.New("connection string is required (e.g. localhost:9080)")
}
return nil
} Type guard
func validConnStr(s string) bool { return strings.TrimSpace(s) != "" } Try / catch
if err := dgraphimport.Import(ctx, addr, outDir); err != nil {
if err.Error() == "connection string cannot be empty" {
return fmt.Errorf("config error: DGRAPH endpoint not set; use --alpha or DGRAPH_ADDR")
}
return err
} Prevention
- Resolve flags/env into a config struct and validate all fields before calling Import.
- Default the endpoint to localhost:9080 in dev tooling.
- Fail fast at startup with a clear message if the endpoint variable is empty.
When it happens
Trigger: Calling dgraphimport.Import (or newClient) with connectionString == "" — e.g. an unset/empty flag, env var, or config field passed straight through.
Common situations: Missing --dgraph/-a style flag, environment variable not set in CI, config struct field forgotten when constructing the Import call, tests intentionally covering the empty-input path.
Related errors
- bulk output directory cannot be empty
- failed to connect to endpoint [%s]: %w
- failed to initiate external snapshot stream: %v
- failed to turn off drain mode: %v
- Tablets are empty in %+v
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/0d70802b76205dbe.
Report an issue: GitHub.