can1357/oh-my-pi · error · DirError

transparent (brush_core::Error)

Error message

transparent (brush_core::Error)

What it means

This is DirError::ShellError, a #[error(transparent)] wrapper around brush_core::Error. The displayed message is entirely delegated to the inner shell error, so the real cause is whatever brush_core operation failed (invalid directory, chdir failure, etc.). It reaches the caller via the `#[from]` conversion whenever a shell-level error occurs inside the dirs builtin.

Source

Thrown at crates/pi-builtins/src/dirs.rs:13

use std::io::Write;

use brush_core::{ExecutionResult, builtins};
use clap::Parser;

#[derive(Debug, thiserror::Error)]
pub(crate) enum DirError {
	/// Directory stack is empty.
	#[error("directory stack is empty")]
	DirStackEmpty,

	/// A shell error occurred.
	#[error(transparent)]
	ShellError(#[from] brush_core::Error),
}

impl From<&DirError> for brush_core::ExecutionExitCode {
	fn from(value: &DirError) -> Self {
		match value {
			DirError::DirStackEmpty => Self::GeneralError,
			DirError::ShellError(e) => e.into(),
		}
	}
}

impl brush_core::BuiltinError for DirError {}

/// Manage the current directory stack.
#[derive(Default, Parser)]
pub(crate) struct DirsCommand {
	/// Clear the directory stack.

View on GitHub (pinned to 9690622007)

Solutions

  1. Look at the transparent inner message — it names the actual shell failure; fix that condition
  2. Verify the target directory exists and is executable (`test -x dir`) before pushd
  3. Check that the directory wasn't deleted/moved by an earlier step in the script
  4. Match on DirError::ShellError and downcast/delegate to brush_core handling if you need structured recovery

Example fix

// before
pushd "$OUT_DIR"  // chdir fails if OUT_DIR unset -> pushd ''
// after
mkdir -p "$OUT_DIR" && pushd "$OUT_DIR"
Defensive patterns

Strategy: try-catch

Validate before calling

// bash: validate target before pushdif [ -d "$dir" ] && [ -x "$dir" ]; then pushd "$dir"; fi

Type guard

fn is_shell_error(e: &DirError) -> Option<&brush_core::Error> { match e { DirError::ShellError(err) => Some(err), _ => None } }

Try / catch

match run() { Err(DirError::ShellError(inner)) => { eprintln!("dirs: {}", inner); /* handle inner kind */ }, Err(other) => return Err(other), Ok(v) => v }

Prevention

When it happens

Trigger: pushd to a nonexistent or unreadable directory (chdir fails inside brush_core), or any brush_core::Error raised while executing dirs-family builtins.

Common situations: Typo'd target directory, directory removed after path was recorded, permission-restricted directories, or scripts running with a restricted cwd.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/ce1cddaa5996d912. Report an issue: GitHub.