atuinsh/atuin · error

there is always at least one potential socket path

Error message

there is always at least one potential socket path

What it means

This is an internal invariant assertion in `existing_socket_path_ctx`: after computing the candidate socket paths, the code calls `.expect("there is always at least one potential socket path")` on the first candidate. The invariant is that `potential_socket_paths_ctx` always yields at least one path (the default). If it ever yields an empty iterator, this panics with that message, indicating a bug in the candidate-generation logic rather than a user-facing problem.

Solutions

  1. Inspect `potential_socket_paths_ctx` and ensure the default socket path is always the first candidate
  2. Verify the SocketCtx passed in resolves a non-empty default path (check XDG_RUNTIME_DIR / home dir resolution)
  3. If you control the caller, fall back to `SocketPath::Default(...).into()` instead of asserting

Example fix

// before
let primary = candidates.next().expect("there is always at least one potential socket path");
// after
let Some(primary) = candidates.next() else {
    return Cow::Owned(ctx.default_socket_path().primary);
};
Defensive patterns

Strategy: type-guard

Validate before calling

// caller-side sanity check
assert!(SocketPath::Default(ctx.default_socket_path().primary).as_path().parent().is_some());

Type guard

fn has_candidates(paths: impl Iterator<Item = PathBuf>) -> bool { paths.count() > 0 }

Try / catch

// expect() panics cannot be caught; verify candidate generation in tests instead
#[test]
fn default_ctx_yields_at_least_one_socket_path() { assert!(paths(ctx).next().is_some()); }

Prevention

When it happens

Trigger: Calling `existing_socket_path` (or `existing_socket_path_ctx`) when `potential_socket_paths_ctx` returns an empty iterator — e.g. a refactor or misconfigured SocketCtx that drops the default path from the candidate list.

Common situations: Almost never hit in practice; arises from code changes to candidate generation, or from constructing a settings/SocketCtx state where XDG/home directory resolution produces no paths.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of atuinsh/atuin@900007c480 (2026-09-19). Data as JSON: /api/errors/d1c02a58e7992440. Report an issue: GitHub.

Appendix: source

Thrown at crates/atuin-client/src/settings/daemon.rs:119

        if let Some(path) = &self.socket_path {
            return SocketPath::UserDefined(path);
        }

        // systemd units typically listen on `%t/atuin.sock`, which is `$XDG_RUNTIME_DIR/atuin.sock`
        // for user units, so we should default to that path when `systemd_socket` is true.
        if self.systemd_socket
            && let Some(path) = ctx.runtime_socket_path()
        {
            return SocketPath::Default(path);
        }

        SocketPath::Default(ctx.default_socket_path().primary)
    }

    fn existing_socket_path_ctx(&self, ctx: impl SocketCtx) -> Cow<'_, Path> {
        let mut candidates = self.potential_socket_paths_ctx(ctx);
        let primary =
            candidates.next().expect("there is always at least one potential socket path");

        if primary.exists() {
            return primary;
        }
        candidates.find(|path| path.exists()).unwrap_or(primary)
    }

    fn potential_socket_paths_ctx(
        &self,
        ctx: impl SocketCtx,
    ) -> impl Iterator<Item = Cow<'_, Path>> {
        let is_user_defined = self.socket_path.is_some();
        let defaults = (!is_user_defined)
            .then(|| self.default_socket_paths(ctx))
            .into_iter()
            .flatten()
            .map(Cow::Owned);
        self.socket_path.as_deref().map(Cow::Borrowed).into_iter().chain(defaults)

View on GitHub (pinned to 900007c480)