{"record":{"id":"2edd2075cf55cfd0","repo":"atuinsh/atuin","slug":"the-vector-is-not-empty","errorCode":null,"errorMessage":"the vector is not empty","messagePattern":"the vector is not empty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/atuin-client/src/history.rs","lineNumber":73,"sourceCode":"    }\n}\n\nimpl From<&str> for AuthorPattern {\n    fn from(value: &str) -> Self {\n        match value {\n            AUTHOR_FILTER_ALL_USER => Self::AllUser,\n            AUTHOR_FILTER_ALL_AGENT => Self::AllAgent,\n            _ => Self::Name(value.to_owned()),\n        }\n    }\n}\n\n/// An author filter that only allows non-agent commands (i.e., [`AuthorPattern::AllUser`]).\n///\n/// This function uses a [`LazyLock`] to avoid building the filter every time.\npub fn all_user_author_filter() -> OrFilter<&'static [AuthorPattern]> {\n    static FILTER: LazyLock<OrFilter<Vec<AuthorPattern>>> = LazyLock::new(|| {\n        OrFilter::from_list(vec![AuthorPattern::AllUser]).expect(\"the vector is not empty\")\n    });\n    FILTER.as_slice_filter()\n}\n\nconst HISTORY_AUTHOR_ENV: &str = \"ATUIN_HISTORY_AUTHOR\";\nconst HISTORY_INTENT_ENV: &str = \"ATUIN_HISTORY_INTENT\";\n\n#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, derive_more::Display)]\n#[display(\"{}\", self.name())]\n#[repr(u16)]\npub enum Version {\n    Zero = 0,\n    One = 1,\n    Two = 2,\n}\n\nimpl Version {\n    pub const VARIANTS: [Self; 3] = [Self::Zero, Self::One, Self::Two];","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/atuinsh/atuin/blob/15fe1318f1df51de604262eb50734c9883d48e7b/crates/atuin-client/src/history.rs#L55-L91","documentation":"Panic inside a LazyLock static initializer: OrFilter::from_list is called with the hardcoded one-element vec![AuthorPattern::AllUser] and is expected to succeed because from_list rejects empty lists. Since the vector is a compile-time constant with one element, the Err branch is unreachable; this expect documents the invariant, it cannot be tripped by any caller or input.","triggerScenarios":"First call to all_user_author_filter() (history filtering that excludes agent-authored commands) would panic only if from_list additionally rejected single-element or specifically AllUser-only lists — behavior that does not exist in the shipped filter implementation. Because LazyLock re-runs an initializer that panicked, a hypothetical failure would repeat on every call rather than poison once.","commonSituations":"None in practice. A developer refactoring AuthorPattern or OrFilter::from_list semantics (e.g., changing the empty-list rule or adding new rejection cases) could accidentally make this invariant false — the panic then fires on the first history query after startup.","solutions":["Recognize this as an internal invariant: no runtime or config change can trigger it, so a crash here means the filter code was modified","If you refactored from_list, re-read its contract: it rejects only empty lists, so ensure one-element lists and AllUser still pass","Keep the vec literal non-empty when editing; if the filter set ever becomes configurable, replace the expect with real error propagation"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// When building your own OrFilters, check the list before construction:\nfn or_filter_or_default(list: Vec<AuthorPattern>) -> OrFilter<Vec<AuthorPattern>> {\n    if list.is_empty() {\n        OrFilter::from_list(vec![AuthorPattern::AllUser]).expect(\"fallback vector is not empty\")\n    } else {\n        OrFilter::from_list(list).expect(\"checked non-empty\")\n    }\n}","typeGuard":"fn is_non_empty_filter_list(list: &[AuthorPattern]) -> bool {\n    !list.is_empty()\n}","tryCatchPattern":null,"preventionTips":["Never pass an empty vec to OrFilter::from_list — that is its only rejection case","Keep all_user_author_filter()'s hardcoded vec untouched; it is a proven non-empty constant","If refactoring from_list's rules, add a test asserting single-element AllUser lists still construct"],"tags":["rust","panic","invariant","unreachable","filter","lazy-static"],"backgroundTag":"empty-argument-list-invariant","analyzedSha":"15fe1318f1df51de604262eb50734c9883d48e7b","analyzedAt":"2026-08-19T08:56:57.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}