{"record":{"id":"c10bb1687b7f9656","repo":"netbirdio/netbird","slug":"invalid-direction-use-in-or-out","errorCode":null,"errorMessage":"invalid direction: use 'in' or 'out'","messagePattern":"invalid direction: use 'in' or 'out'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"client/cmd/trace.go","lineNumber":45,"sourceCode":"\tdebugCmd.AddCommand(traceCmd)\n\n\ttraceCmd.Flags().StringP(\"protocol\", \"p\", \"tcp\", \"Protocol (tcp/udp/icmp)\")\n\ttraceCmd.Flags().Uint16(\"sport\", 0, \"Source port\")\n\ttraceCmd.Flags().Uint16(\"dport\", 0, \"Destination port\")\n\ttraceCmd.Flags().Uint8(\"icmp-type\", 0, \"ICMP type\")\n\ttraceCmd.Flags().Uint8(\"icmp-code\", 0, \"ICMP code\")\n\ttraceCmd.Flags().Bool(\"syn\", false, \"TCP SYN flag\")\n\ttraceCmd.Flags().Bool(\"ack\", false, \"TCP ACK flag\")\n\ttraceCmd.Flags().Bool(\"fin\", false, \"TCP FIN flag\")\n\ttraceCmd.Flags().Bool(\"rst\", false, \"TCP RST flag\")\n\ttraceCmd.Flags().Bool(\"psh\", false, \"TCP PSH flag\")\n\ttraceCmd.Flags().Bool(\"urg\", false, \"TCP URG flag\")\n}\n\nfunc tracePacket(cmd *cobra.Command, args []string) error {\n\tdirection := strings.ToLower(args[0])\n\tif direction != \"in\" && direction != \"out\" {\n\t\treturn fmt.Errorf(\"invalid direction: use 'in' or 'out'\")\n\t}\n\n\tprotocol := cmd.Flag(\"protocol\").Value.String()\n\tif protocol != \"tcp\" && protocol != \"udp\" && protocol != \"icmp\" {\n\t\treturn fmt.Errorf(\"invalid protocol: use tcp/udp/icmp\")\n\t}\n\n\tsport, err := cmd.Flags().GetUint16(\"sport\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid source port: %v\", err)\n\t}\n\tdport, err := cmd.Flags().GetUint16(\"dport\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid destination port: %v\", err)\n\t}\n\n\t// For TCP/UDP, generate random ephemeral port (49152-65535) if not specified\n\tif protocol != \"icmp\" {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/cmd/trace.go#L27-L63","documentation":"Thrown by tracePacket (client/cmd/trace.go:45), the handler for 'netbird debug trace <direction> <source-ip> <dest-ip>'. args[0] is lowercased and must equal \"in\" or \"out\"; anything else is rejected before any daemon call. Pure CLI argument validation - the daemon is never contacted.","triggerScenarios":"Invoking 'netbird debug trace ingress 10.0.0.1 10.0.0.2' or with 'IN '/' inbound'/'input' - any first argument whose lowercase form is not exactly 'in' or 'out' (for example 'ingress', 'egress', 'tx', 'rx').","commonSituations":"Muscle memory from other tools that use ingress/egress or rx/tx terminology; scripts passing a variable that is empty or misspelled.","solutions":["Use exactly 'in' or 'out' as the first positional argument (case-insensitive: 'IN' works)","Check the command examples in 'netbird debug trace --help'"],"exampleFix":"// before\nArgs: cobra.ExactArgs(3),\nRunE: tracePacket,\n\n// after: reject bad direction at the Args layer\nArgs: func(cmd *cobra.Command, args []string) error {\n    if len(args) != 3 {\n        return fmt.Errorf(\"requires <direction> <source-ip> <dest-ip>\")\n    }\n    if d := strings.ToLower(args[0]); d != \"in\" && d != \"out\" {\n        return fmt.Errorf(\"invalid direction %q: use 'in' or 'out'\", args[0])\n    }\n    return nil\n},","handlingStrategy":"validation","validationCode":"dir := strings.ToLower(os.Args[1])\nif dir != \"in\" && dir != \"out\" {\n    log.Fatalf(\"direction must be 'in' or 'out', got %q\", os.Args[1])\n}\n// only then exec netbird debug trace","typeGuard":"func isTraceDirection(s string) bool {\n    d := strings.ToLower(s)\n    return d == \"in\" || d == \"out\"\n}","tryCatchPattern":null,"preventionTips":["Read 'netbird debug trace --help' examples before scripting","Validate generated command lines in scripts before exec"],"tags":["cli","validation","trace","user-input","netbird"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}