netbirdio/netbird · warning

invalid duration format: %v

Error message

invalid duration format: %v

What it means

runForDuration parses its first positional argument with time.ParseDuration and wraps failure here. Go duration strings require a unit suffix and use specific abbreviations: '30s', '5m', '1h30m', '500ms' are valid; '30' (no unit), '1min', '1hr', '1 sec' (space), '1h.5m', or a comma are not. This is pure client-side validation before anything is sent to the daemon.

Source

Thrown at client/cmd/debug.go:235

		//nolint
		return fmt.Errorf("unknown log level: %s. Available levels are: panic, fatal, error, warn, info, debug, trace\n", args[0])
	}

	_, err = client.SetLogLevel(cmd.Context(), &proto.SetLogLevelRequest{
		Level: level,
	})
	if err != nil {
		return fmt.Errorf("failed to set log level: %v", status.Convert(err).Message())
	}

	cmd.Println("Log level set successfully to", args[0])
	return nil
}

func runForDuration(cmd *cobra.Command, args []string) error {
	duration, err := time.ParseDuration(args[0])
	if err != nil {
		return fmt.Errorf("invalid duration format: %v", err)
	}

	anonymizeEnabled, anonymizeLevel, err := effectiveAnonymize()
	if err != nil {
		return err
	}

	conn, err := getClient(cmd)
	if err != nil {
		return err
	}
	defer func() {
		if err := conn.Close(); err != nil {
			log.Errorf(errCloseConnection, err)
		}
	}()

	client := proto.NewDaemonServiceClient(conn)

View on GitHub (pinned to 93e97f4bf1)

Solutions

  1. Append a Go unit: s (seconds), m (minutes), h (hours) — e.g. 90s, 5m, 2h; combine like 1h30m
  2. Avoid spaces inside the value; quote it if it comes from a variable: netbird debug up --run-for "${d}"
  3. If sourcing the value from humans, validate/normalize it in the script first (e.g. append 's' when it is a bare number)

Example fix

# before
netbird debug up --run-for 30
# -> invalid duration format: ...

# after
netbird debug up --run-for 30s
Defensive patterns

Strategy: validation

Validate before calling

// Validate before invoking the CLI:
if _, err := time.ParseDuration(val); err != nil {
    return fmt.Errorf("invalid duration %q (need Go syntax like 30s, 5m, 1h30m)", val)
}

Type guard

// Guard for bare numbers coming from config/users — promote to seconds:
func normalizeDuration(s string) (time.Duration, error) {
    if d, err := time.ParseDuration(s); err == nil {
        return d, nil
    }
    if n, err := strconv.Atoi(s); err == nil {
        return time.Duration(n) * time.Second, nil
    }
    return 0, fmt.Errorf("invalid duration %q", s)
}

Prevention

When it happens

Trigger: netbird debug up --run-for 30 (missing unit); '10min' instead of '10m'; '1 hr' with a space splitting into two args; locale habits like '1,5h' comma decimal; a shell variable that is empty or contains whitespace.

Common situations: Scripts building the duration from numbers without appending a unit; users expecting cron-style or natural-language durations; copy-pasting values from tools that accept bare seconds.

Related errors


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