{"record":{"id":"cf63c4d693a1ea81","repo":"gastownhall/beads","slug":"server-host-cannot-be-empty-omit-the-flag-to-us","errorCode":null,"errorMessage":"--server-host cannot be empty; omit the flag to use BEADS_DOLT_SERVER_HOST or the default (%s)","messagePattern":"--server-host cannot be empty; omit the flag to use BEADS_DOLT_SERVER_HOST or the default \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init.go","lineNumber":3185,"sourceCode":"\n// resolveExplicitServerConnEnv turns the explicit --server-* flags into the\n// set of environment changes promoteExplicitServerConnFlags will apply. It\n// validates every flag before returning, so a later invalid flag cannot leave\n// an earlier valid one already applied to the process environment.\n//\n// Because a socket outranks host/port everywhere downstream, selecting TCP\n// explicitly (--server-host or --server-port) also clears an ambient\n// BEADS_DOLT_SERVER_SOCKET unless --server-socket was itself given. An\n// explicitly empty --server-socket clears the ambient socket too: empty is\n// the documented \"use TCP\" value (see configfile.GetDoltServerSocket).\n// Changed-but-empty host/user and out-of-range port values fail explicitly\n// rather than being silently ignored.\nfunc resolveExplicitServerConnEnv(cmd *cobra.Command) ([]serverConnEnvMutation, error) {\n\tvar muts []serverConnEnvMutation\n\tif cmd.Flags().Changed(\"server-host\") {\n\t\tv, _ := cmd.Flags().GetString(\"server-host\")\n\t\tif v == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"--server-host cannot be empty; omit the flag to use BEADS_DOLT_SERVER_HOST or the default (%s)\", configfile.DefaultDoltServerHost)\n\t\t}\n\t\tmuts = append(muts, serverConnEnvMutation{key: \"BEADS_DOLT_SERVER_HOST\", value: v})\n\t}\n\tif cmd.Flags().Changed(\"server-port\") {\n\t\tv, _ := cmd.Flags().GetInt(\"server-port\")\n\t\tif v < 1 || v > 65535 {\n\t\t\treturn nil, fmt.Errorf(\"--server-port must be between 1 and 65535, got %d; omit the flag to use BEADS_DOLT_SERVER_PORT or the default (%d)\", v, configfile.DefaultDoltServerPort)\n\t\t}\n\t\tmuts = append(muts, serverConnEnvMutation{key: \"BEADS_DOLT_SERVER_PORT\", value: strconv.Itoa(v)})\n\t}\n\tif cmd.Flags().Changed(\"server-user\") {\n\t\tv, _ := cmd.Flags().GetString(\"server-user\")\n\t\tif v == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"--server-user cannot be empty; omit the flag to use BEADS_DOLT_SERVER_USER or the default (%s)\", configfile.DefaultDoltServerUser)\n\t\t}\n\t\tmuts = append(muts, serverConnEnvMutation{key: \"BEADS_DOLT_SERVER_USER\", value: v})\n\t}\n\tswitch {","sourceCodeStart":3167,"sourceCodeEnd":3203,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init.go#L3167-L3203","documentation":"resolveExplicitServerConnEnv validates the --server-host flag when the user explicitly sets it. An explicitly passed empty string is treated as a mistake rather than falling back to env/default, so it returns this error listing the fallback order (BEADS_DOLT_SERVER_HOST env var, then configfile.DefaultDoltServerHost). The point is to prevent flags from being silently ignored.","triggerScenarios":"Invoking any command that promotes server connection flags (via promoteExplicitServerConnFlags) with `--server-host \"\"` explicitly on the command line.","commonSituations":"Script variables that expand to empty (e.g. --server-host \"$MY_HOST\" with MY_HOST unset); copy-pasted examples with a blank value; attempting to 'unset' the host by passing an empty flag.","solutions":["Omit --server-host entirely to use BEADS_DOLT_SERVER_HOST or the built-in default","Export BEADS_DOLT_SERVER_HOST=<host> instead of passing an empty flag","Fix the wrapping script so the variable is non-empty before invoking bd"],"exampleFix":"// before\nbd init --server-host \"\"\n// after\nbd init --server-host dolt.example.internal\n# or simply omit the flag and set the env:\nexport BEADS_DOLT_SERVER_HOST=dolt.example.internal","handlingStrategy":"validation","validationCode":"if [ -z \"$SERVER_HOST\" ]; then unset SERVER_HOST; fi  # don't pass empty vars to --server-host","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil && strings.Contains(err.Error(), \"--server-host cannot be empty\") { /* omit the flag or set env */ }","preventionTips":["Only pass --server-host with a verified non-empty value","Prefer BEADS_DOLT_SERVER_HOST env over empty flag overrides","In scripts, guard: [ -n \"$HOST_VAR\" ] before building the command","Never use empty flag values to 'reset' configuration"],"tags":["cli","validation","dolt-server","flags"],"backgroundTag":"empty-flag-value","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}