netbirdio/netbird · error

set env and flags

Error message

set env and flags: %v

What it means

The login command's early setup step failed: setEnvAndFlags reconciles environment variables with CLI flags (management URL, setup key path, log settings) and returns an error on invalid or conflicting combinations before any login attempt is made.

Solutions

  1. Read the nested error to see which flag or env var failed validation
  2. Check for conflicting NETBIRD_* environment variables versus command flags
  3. Unset the offending variable or correct the flag value and retry login
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at client/cmd/login.go:47 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16). Data as JSON: /api/errors/18f0b2cfed62d8f3. Report an issue: GitHub.

Appendix: source

Thrown at client/cmd/login.go:47

// refresh an SSO-tracked peer — see auth.errSetupKeyOnSSOExpiredPeer).
var extendSessionFlag bool

func init() {
	loginCmd.PersistentFlags().BoolVar(&noBrowser, noBrowserFlag, false, noBrowserDesc)
	loginCmd.PersistentFlags().BoolVar(&showQR, showQRFlag, false, showQRDesc)
	loginCmd.PersistentFlags().StringVar(&profileName, profileNameFlag, "", profileNameDesc)
	loginCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "(DEPRECATED) Netbird config file location")
	loginCmd.PersistentFlags().BoolVar(&extendSessionFlag, "extend", false,
		"refresh the SSO session expiry without tearing down the tunnel (requires an active connection)")
}

var loginCmd = &cobra.Command{
	Use:   "login",
	Short: "Log in to the NetBird network",
	Long:  "Log in to the NetBird network using a setup key or SSO",
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := setEnvAndFlags(cmd); err != nil {
			return fmt.Errorf("set env and flags: %v", err)
		}

		ctx := internal.CtxInitState(context.Background())

		if hostName != "" {
			// nolint
			ctx = context.WithValue(ctx, system.DeviceNameCtxKey, hostName)
		}
		username, err := user.Current()
		if err != nil {
			return fmt.Errorf("get current user: %v", err)
		}

		pm := profilemanager.NewProfileManager()

		activeProf, err := getActiveProfile(cmd.Context(), pm, profileName, username.Username)
		if err != nil {
			return fmt.Errorf("get active profile: %v", err)

View on GitHub (pinned to 93e97f4bf1)