use ozzy_proto::layout::LayoutError;
use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum OperationCodecError {
#[error("invalid consumer group plan format")]
InvalidGroupPlan,
#[error("unsupported consumer assignment format {0}")]
UnsupportedAssignmentFormat(u8),
#[error("invalid append results")]
InvalidAppendResults,
#[error("unsupported operation kind {0}")]
UnsupportedOperationKind(u16),
#[error("truncated operation body: need {needed} bytes, have {available}")]
Truncated {
needed: usize,
available: usize,
},
#[error("operation body has {0} trailing bytes")]
TrailingBytes(usize),
#[error("invalid UTF-8 in {0}")]
InvalidUtf8(&'static str),
#[error("{0} must not be empty")]
EmptyValue(&'static str),
#[error("invalid optional-value tag {0}")]
InvalidOptionTag(u8),
#[error("invalid progress-owner tag {0}")]
InvalidProgressOwnerTag(u8),
#[error("retention policy version or flags are unsupported")]
InvalidRetention,
#[error("append operation must contain a batch and each batch a record")]
EmptyAppend,
#[error("append record must contain at least one message part")]
EmptyRecordParts,
#[error("prepared append payload is invalid or does not match its raw record view")]
InvalidPreparedPayload,
#[error("APPEND payload compression failed")]
AppendCompression,
#[error("append sequence or offset range overflows")]
AppendPositionOverflow,
#[error("consumer-group progress requires a member and assignment epoch")]
MissingProgressAssignment,
#[error("standalone subscription progress cannot carry an assignment")]
UnexpectedProgressAssignment,
#[error("integer or length arithmetic overflow")]
LengthOverflow,
#[error("operation output allocation failed")]
OutputAllocation,
#[error("{kind} limit exceeded: {actual} > {limit}")]
LimitExceeded {
kind: &'static str,
actual: usize,
limit: usize,
},
#[error("record range is outside its batch")]
RecordRange,
#[error("record list cannot extend another representation")]
RecordListKind,
}
impl From<LayoutError> for OperationCodecError {
fn from(error: LayoutError) -> Self {
match error {
LayoutError::Truncated { needed, available } => Self::Truncated { needed, available },
LayoutError::Trailing(bytes) => Self::TrailingBytes(bytes),
LayoutError::Overflow { .. } => Self::LengthOverflow,
}
}
}