{"record":{"id":"54b3336930a63da2","repo":"nautechsystems/nautilus_trader","slug":"division-result-should-be-non-zero-after-validatio","errorCode":null,"errorMessage":"Division result should be non-zero after validation","messagePattern":"Division result should be non-zero after validation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/network/src/ratelimiter/quota.rs","lineNumber":165,"sourceCode":"        let t_u64 = t.as_u64();\n        let tau_u64 = tau.as_u64();\n\n        // Validate division won't be zero or overflow\n        assert!(t_u64 != 0, \"Invalid GCRA parameter: t cannot be zero\");\n\n        let division_result = tau_u64 / t_u64;\n        assert!(\n            division_result != 0,\n            \"Invalid GCRA parameters: tau/t results in zero burst capacity\"\n        );\n        assert!(\n            u32::try_from(division_result).is_ok(),\n            \"Invalid GCRA parameters: tau/t exceeds u32::MAX\"\n        );\n\n        // We've verified the result is non-zero and fits in u32\n        let max_burst = NonZeroU32::new(division_result as u32)\n            .expect(\"Division result should be non-zero after validation\");\n        let replenish_1_per = t.into();\n        Self {\n            max_burst,\n            replenish_1_per,\n        }\n    }\n}\n","sourceCodeStart":147,"sourceCodeEnd":173,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/network/src/ratelimiter/quota.rs#L147-L173","documentation":"Quota::from_gcra_parameters computes max_burst = tau/t and asserts the result fits u32 and is non-zero. The assertions above guarantee both, so this expect is a defensive invariant; it only fires if the preceding validation logic is wrong (division_result == 0 slipping through).","triggerScenarios":"Calling Quota::from_gcra_parameters with tau/t values whose validated division_result is zero — normally unreachable because earlier asserts check non-zero and u32 fit; a logic bug or integer truncation (e.g. tau < t yielding 0 after division) could trigger it.","commonSituations":"Constructing a quota from raw GCRA parameters where tau (capacity interval) is smaller than t (cell interval), producing a truncated zero burst; misconfigured rate-limit configs from external systems.","solutions":["Validate that tau >= t (so the division is at least 1) before calling from_gcra_parameters.","Check the config values for the GCRA parameters; tau/t=0 is an invalid quota definition.","If reachable with valid inputs, report as a bug in the validation order."],"exampleFix":"// before\nlet quota = Quota::from_gcra_parameters(tau, t); // panics if tau/t truncates to 0\n// after\nassert!(tau >= t, \"GCRA tau must be >= t to yield a non-zero burst\");\nlet quota = Quota::from_gcra_parameters(tau, t);","handlingStrategy":"validation","validationCode":"fn valid_gcra(tau: u64, t: u64) -> bool { tau >= t && tau / t > 0 && tau / t <= u32::MAX as u64 }","typeGuard":null,"tryCatchPattern":"let quota = std::panic::catch_unwind(|| Quota::from_gcra_parameters(tau, t));","preventionTips":["Ensure tau >= t before constructing the quota","Check tau/t fits in u32 before calling","Validate rate-limit parameters at config load time"],"tags":["rust","rate-limiting","quota","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}