Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prefixed writer no longer includes prefix length in bytes written (
#6032) ### Description When hooking up the prefixed writer as part of task graph execution I encountered: ``` [0 olszewski@chriss-mbp] /tmp/pnpm-test $ turbo_dev build --experimental-rust-codepath docs:build: next build web:build: next build docs:build: thread 'tokio-runtime-worker' panicked at /rustc/3223b0b5e8dadda3f76c3fd1a8d6c5addc09599e/library/std/src/io/mod.rs:1581:36: range start index 22 out of range for slice of length 1 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace web:build: thread 'tokio-runtime-worker' panicked at /rustc/3223b0b5e8dadda3f76c3fd1a8d6c5addc09599e/library/std/src/io/mod.rs:1581:36: range start index 21 out of range for slice of length 1 thread 'main' panicked at crates/turborepo-lib/src/task_graph/visitor.rs:259:20: task executor panicked: JoinError::Panic(Id(28), ...) ``` After a bit of digging, I found that this was caused by us violating part of the `Write` trait, specifically our `write` return value: > If the return value is Ok(n) then n must satisfy n <= buf.len() Where we would return `prefix.len() + buf.len()` which upstream would cause and index out of bounds panic. This PR: - Now returns `buf.len()` in `write` so we return values that callers expect - Refactor `PrefixedWriter` to eagerly apply the styled writer instead of applying it on every write call. ### Testing Instructions Added quick unit tests. Real test for the panic fix is use in the process manager hookup PR: https://github.com/vercel/turbo/tree/olszewski/hook_up_process_manager Closes TURBO-1363 Co-authored-by: Chris Olszewski <Chris Olszewski>
- Loading branch information