Hmbown/CodeWhale · error · io::Error

project hooks file exceeds the 1 MiB limit

Error message

project hooks file exceeds the 1 MiB limit

What it means

This error means the project hooks configuration file is larger than the allowed 1 MiB (PROJECT_HOOKS_FILE_MAX_BYTES). The library reads at most limit+1 bytes with a bounded take() and throws InvalidData when the content exceeds the limit, protecting against oversized or pathological hooks files.

Solutions

  1. Trim the project hooks file below 1 MiB: remove unused hook entries and comments
  2. Move large or generated hook logic into an external script the hooks file invokes, keeping the config small
  3. Split hooks across plugin-level configuration instead of one giant project file

Example fix

// before
hooks.json: 1.4 MiB of inline commands
// after
hooks.json references scripts: {"post-edit": {"command": "./hooks/post-edit.sh"}}
Defensive patterns

Strategy: validation

Validate before calling

const LIMIT: u64 = 1024 * 1024;
let md = std::fs::metadata(hooks_path)?;
if md.len() > LIMIT {
    return Err("project hooks file exceeds 1 MiB; trim it before loading");
}

Try / catch

match load_plugin_hook_component(path) {
    Ok(hooks) => register(hooks),
    Err(e) if e.kind() == std::io::ErrorKind::InvalidData => {
        eprintln!("hooks file too large (>1 MiB); reduce it");
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Calling load_plugin_hook_component when the project hooks file on disk exceeds PROJECT_HOOKS_FILE_MAX_BYTES (1 MiB) — detected by reading limit+1 bytes and finding contents.len() > limit.

Common situations: A generated or vendored hooks file grew unbounded; a script appended repeatedly to hooks config; someone pasted a large blob into the hooks JSON/YAML.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/eaca556a7603ae42. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/hooks/config.rs:16

use serde::{Deserialize, Serialize};
use std::io::Read as _;
use std::path::{Path, PathBuf};

/// Project hook files are executable configuration and must not become an
/// unbounded startup allocation merely because a trusted repository supplied
/// a very large file.
const PROJECT_HOOKS_FILE_MAX_BYTES: usize = 1024 * 1024;

pub(super) fn read_project_hooks_file(path: &Path) -> std::io::Result<String> {
    let file = std::fs::File::open(path)?;
    let mut contents = String::new();
    file.take((PROJECT_HOOKS_FILE_MAX_BYTES + 1) as u64)
        .read_to_string(&mut contents)?;
    if contents.len() > PROJECT_HOOKS_FILE_MAX_BYTES {
        return Err(std::io::Error::new(
            std::io::ErrorKind::InvalidData,
            "project hooks file exceeds the 1 MiB limit",
        ));
    }
    Ok(contents)
}

/// Events that can trigger hook execution
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum HookEvent {
    /// Triggered when a new session starts
    SessionStart,
    /// Triggered when a session ends (quit, Ctrl+C)
    SessionEnd,
    /// Triggered before a user message is sent to the LLM
    MessageSubmit,
    /// Triggered before a tool is executed

View on GitHub (pinned to 73e0f67d83)