playhard-launcher 0.1.1

Chrome launcher and profile management for the Playhard Rust browser automation stack.
Documentation
use std::{path::PathBuf, time::Duration};

use thiserror::Error;

/// Errors produced by the launcher crate.
#[derive(Debug, Error)]
pub enum LaunchError {
    /// Chrome could not be found through either the primary or fallback lookup.
    #[error("could not locate Chrome: {primary}; fallback lookup also failed: {fallback}")]
    ChromeNotFound {
        /// Error emitted by the primary lookup path.
        primary: String,
        /// Error emitted by the fallback stable-channel lookup.
        fallback: String,
    },

    /// The caller supplied an explicit executable path that does not exist.
    #[error("explicit Chrome executable does not exist: {0}")]
    ExecutableNotFound(PathBuf),

    /// Creating or opening the requested profile directory failed.
    #[error("failed to create or access the Chrome profile directory: {source}")]
    ProfileDirectory {
        /// The underlying filesystem error.
        #[source]
        source: std::io::Error,
    },

    /// Spawning the Chrome process failed.
    #[error("failed to spawn Chrome: {source}")]
    Spawn {
        /// The underlying process spawn error.
        #[source]
        source: std::io::Error,
    },

    /// Inspecting the Chrome process state failed.
    #[error("failed to inspect Chrome process state: {source}")]
    ProcessState {
        /// The underlying process state error.
        #[source]
        source: std::io::Error,
    },

    /// Chrome did not write `DevToolsActivePort` before startup timed out.
    #[error("timed out after {timeout:?} waiting for {path}")]
    DevToolsActivePortTimeout {
        /// The expected `DevToolsActivePort` file path.
        path: PathBuf,
        /// The maximum amount of time that was waited.
        timeout: Duration,
    },

    /// Reading the `DevToolsActivePort` file failed.
    #[error("failed to read {path}: {source}")]
    DevToolsActivePortRead {
        /// The attempted `DevToolsActivePort` file path.
        path: PathBuf,
        /// The underlying filesystem error.
        #[source]
        source: std::io::Error,
    },

    /// The `DevToolsActivePort` file was present but malformed.
    #[error("invalid DevToolsActivePort file at {path}")]
    InvalidDevToolsActivePort {
        /// The malformed file path.
        path: PathBuf,
    },

    /// Pipe mode was requested but Chrome did not provide both pipe handles.
    #[error("remote debugging pipe was requested but Chrome did not provide piped stdio")]
    MissingPipeHandles,

    /// Chrome exited before exposing its requested debugging transport.
    #[error("Chrome exited before it became ready")]
    ChromeExitedEarly,
}