{"record":{"id":"67c15c9bbc0cb267","repo":"jdx/mise","slug":"firewall-port-range-start-end-is-invalid","errorCode":null,"errorMessage":"firewall port range {start}-{end} is invalid","messagePattern":"firewall port range (.+?)-(.+?) is invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/firewall.rs","lineNumber":205,"sourceCode":"#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]\npub(crate) struct FirewallPort {\n    start: u16,\n    end: u16,\n}\n\nimpl FirewallPort {\n    fn from_toml(value: FirewallPortToml) -> Result<Self> {\n        let (start, end) = match value {\n            FirewallPortToml::Single(port) => (port, port),\n            FirewallPortToml::Range(range) => {\n                let Some((start, end)) = range.split_once(['-', ':']) else {\n                    bail!(\"firewall port '{range}' must be a number or inclusive range\")\n                };\n                (start.parse()?, end.parse()?)\n            }\n        };\n        if start == 0 || end == 0 || start > end {\n            bail!(\"firewall port range {start}-{end} is invalid\");\n        }\n        Ok(Self { start, end })\n    }\n\n    fn contains(self, port: u16) -> bool {\n        self.start <= port && port <= self.end\n    }\n\n    fn render(self, separator: char) -> String {\n        if self.start == self.end {\n            self.start.to_string()\n        } else {\n            format!(\"{}{separator}{}\", self.start, self.end)\n        }\n    }\n}\n\n#[derive(Clone, Debug, Deserialize)]","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/firewall.rs#L187-L223","documentation":"After splitting a firewall port range into endpoints and parsing both as `u16`, `FirewallPort::from_toml` validates that neither bound is 0 and that start <= end. Violating any of these yields this error with the parsed (possibly mis-ordered) bounds, since a zero port is invalid and an inverted range matches nothing.","triggerScenarios":"Config values like `\"9000-8000\"` (inverted), `\"0-80\"` or `\"80-0\"` (zero bound), or values > 65535 that fail `u16::parse` earlier but whose parse errors surface similarly from this function.","commonSituations":"Hand-written firewall rules with swapped endpoints, off-by-one/zero typos, or copying Linux iptables-style `0` semantics that this parser rejects.","solutions":["Order the endpoints ascending, e.g. `\"8000-9000\"`","Use port numbers 1-65535; replace 0 with a real port","For a single port, write it as a number rather than a range"],"exampleFix":"// before (mise.toml)\n[[firewall.rules]]\nports = [\"9000-8000\"]\n\n// after\n[[firewall.rules]]\nports = [\"8000-9000\"]","handlingStrategy":"validation","validationCode":"function validRange(a, b) {\n  return a >= 1 && b >= 1 && a <= 65535 && b <= 65535 && a <= b;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write ranges with the lower port first","Keep all ports within 1-65535","Never use port 0 in firewall rules"],"tags":["firewall","config","port","range"],"backgroundTag":"value-out-of-range","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}