use std::io;
use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("invalid input JSON: {0}")]
InvalidJson(#[source] serde_json::Error),
#[error("read input from stdin: {0}")]
StdinRead(#[source] io::Error),
#[error("missing env var {0:?} (set by the harness per ARCH §3.3)")]
MissingEnv(&'static str),
#[error(
"malformed address {given:?}: expected \
steps/<agent-id>/<NNN>/tools/<tool-id>/output.json#<stdout|stderr>@<byte offset>, \
copied verbatim from the marker in the cut result"
)]
Malformed { given: String },
#[error(
"address names agent {theirs:?}, and you are {ours:?}: \
an agent may page only its own tool captures"
)]
ForeignAgent { theirs: String, ours: String },
#[error("no capture at {record}: {source}", record = record.display())]
NoRecord {
record: PathBuf,
#[source]
source: io::Error,
},
#[error("capture at {record} did not parse: {source}", record = record.display())]
Unreadable {
record: PathBuf,
#[source]
source: serde_json::Error,
},
#[error("offset {offset} is past the end of {stream} ({total} bytes)")]
PastEnd {
offset: usize,
stream: String,
total: usize,
},
#[error("write the page: {0}")]
Write(#[source] io::Error),
}