netbirdio/netbird · warning
duration must not be negative
Error message
duration must not be negative
What it means
buildCaptureRequest reads the --duration/-d flag and refuses a negative value: a non-zero negative duration would be meaningless for the capture (the daemon stops the stream after the elapsed duration). It is a pure client-side flag validation, raised before the gRPC stream is opened.
Source
Thrown at client/cmd/capture.go:123
}
func buildCaptureRequest(cmd *cobra.Command, args []string) (*proto.StartCaptureRequest, error) {
req := &proto.StartCaptureRequest{}
if len(args) > 0 {
expr := strings.Join(args, " ")
if _, err := capture.ParseFilter(expr); err != nil {
return nil, fmt.Errorf("invalid filter: %w", err)
}
req.FilterExpr = expr
}
if snap, _ := cmd.Flags().GetUint32("snap-len"); snap > 0 {
req.SnapLen = snap
}
if d, _ := cmd.Flags().GetDuration("duration"); d != 0 {
if d < 0 {
return nil, fmt.Errorf("duration must not be negative")
}
req.Duration = durationpb.New(d)
}
req.Verbose, _ = cmd.Flags().GetBool("verbose")
req.Ascii, _ = cmd.Flags().GetBool("ascii")
outPath, _ := cmd.Flags().GetString("output")
forcePcap, _ := cmd.Flags().GetBool("pcap")
req.TextOutput = !forcePcap && outPath == ""
return req, nil
}
func streamCapture(ctx context.Context, cmd *cobra.Command, stream proto.DaemonService_StartCaptureClient, out io.Writer) error {
for {
pkt, err := stream.Recv()
if err != nil {
if ctx.Err() != nil {View on GitHub (pinned to 93e97f4bf1)
Solutions
- Pass a positive duration (netbird debug capture -d 30s) or omit the flag to run until Ctrl+C
- If the value is computed, clamp it: use the value only when > 0, e.g. netbird debug capture -d "${remaining}s" after checking remaining>0
- Double-check for a stray leading dash introduced by flag style: --duration=-5s is parsed as the value -5s, which this check catches
Example fix
# before: computed value may be negative
netbird debug capture -d $((END-NOW))s
# after: guard in the caller or clamp
remaining=$((END-NOW)); [ "$remaining" -lt 1 ] && remaining=1
netbird debug capture -d ${remaining}s Defensive patterns
Strategy: validation
Validate before calling
// In scripts, clamp before invoking:
d=${CALC_SECONDS:-0}
if [ "$d" -gt 0 ] 2>/dev/null; then DUR="${d}s"; else DUR=""; fi
netbird debug capture -d "$DUR" # empty resets to default 0 Prevention
- Treat duration as an unsigned value in any wrapper; clamp negatives to zero (which means run-forever) or a floor of 1s
- Compute durations from max(1, END-NOW) so a slow start cannot produce a negative budget
When it happens
Trigger: Passing an explicitly negative duration: netbird debug capture --duration=-30s or -d -1m; a shell alias or script computing the duration from a subtraction that went negative (END-START where END < START, producing e.g. -45s). Note d != 0 gates the check, so zero means 'until interrupted' and is allowed.
Common situations: Automation scripts that compute a countdown and pass it through without clamping; typo of the minus sign; reusing a timeout budget variable that has already been spent.
Related errors
- invalid filter: %w
- invalid duration format: %v
- invalid anonymize level %q: use %q or %q
- --expiration must be a positive duration (e.g., 720h, 365d,
- cannot specify both --all flag and state name
AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16).
Data as JSON: /api/errors/98d05617ceb85d83.
Report an issue: GitHub.