{"record":{"id":"0d70802b76205dbe","repo":"dgraph-io/dgraph","slug":"connection-string-cannot-be-empty","errorCode":null,"errorMessage":"connection string cannot be empty","messagePattern":"connection string cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dgraph/cmd/dgraphimport/import_client.go","lineNumber":31,"sourceCode":"\t\"math\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/dgraph-io/badger/v4\"\n\t\"github.com/dgraph-io/dgo/v250\"\n\t\"github.com/dgraph-io/dgo/v250/protos/api\"\n\t\"github.com/dgraph-io/ristretto/v2/z\"\n\n\t\"github.com/golang/glog\"\n\t\"golang.org/x/sync/errgroup\"\n)\n\n// newClient creates a new import client with the specified endpoint and gRPC options.\nfunc newClient(connectionString string) (api.DgraphClient, error) {\n\tif connectionString == \"\" {\n\t\treturn nil, fmt.Errorf(\"connection string cannot be empty\")\n\t}\n\n\tdg, err := dgo.Open(connectionString)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to connect to endpoint [%s]: %w\", connectionString, err)\n\t}\n\n\tglog.Infof(\"[import] Successfully connected to Dgraph endpoint: %s\", connectionString)\n\treturn dg.GetAPIClients()[0], nil\n}\n\nfunc Import(ctx context.Context, connectionString string, bulkOutDir string) error {\n\tif bulkOutDir == \"\" {\n\t\treturn fmt.Errorf(\"bulk output directory cannot be empty\")\n\t}\n\n\tdg, err := newClient(connectionString)\n\tif err != nil {","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/dgraphimport/import_client.go#L13-L49","documentation":"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.","triggerScenarios":"Calling dgraphimport.Import (or newClient) with connectionString == \"\" — e.g. an unset/empty flag, env var, or config field passed straight through.","commonSituations":"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.","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."],"exampleFix":"// before\nerr := dgraphimport.Import(ctx, os.Getenv(\"DGRAPH_ADDR\"), outDir) // env unset → \"\"\n// after\naddr := os.Getenv(\"DGRAPH_ADDR\")\nif addr == \"\" { addr = \"localhost:9080\" }\nerr := dgraphimport.Import(ctx, addr, outDir)","handlingStrategy":"validation","validationCode":"if err := validateAddr(addr); err != nil { return err }\n\nfunc validateAddr(addr string) error {\n    if strings.TrimSpace(addr) == \"\" {\n        return errors.New(\"connection string is required (e.g. localhost:9080)\")\n    }\n    return nil\n}","typeGuard":"func validConnStr(s string) bool { return strings.TrimSpace(s) != \"\" }","tryCatchPattern":"if err := dgraphimport.Import(ctx, addr, outDir); err != nil {\n    if err.Error() == \"connection string cannot be empty\" {\n        return fmt.Errorf(\"config error: DGRAPH endpoint not set; use --alpha or DGRAPH_ADDR\")\n    }\n    return err\n}","preventionTips":["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."],"tags":["validation","grpc","configuration","import"],"backgroundTag":"empty-connection-string","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}