Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/coln-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ rustyline = { version = "18.0.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.149"
shlex = "2.0.1"
thiserror = "2.0.18"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = [
"env-filter",
Expand Down
23 changes: 4 additions & 19 deletions packages/coln-store/src/commit/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

use std::{
collections::{BTreeSet, HashMap},
error::Error,
fmt,
};
use std::collections::{BTreeSet, HashMap};

use crate::commit::{Commit, CommitHash};

Expand All @@ -23,25 +19,14 @@ pub struct CommitGraph {
heads: BTreeSet<CommitHash>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
pub enum CommitGraphError {
#[error("commit graph has no root commit")]
MissingRoot,
#[error("commit graph has multiple root commits")]
MultipleRoots,
}

impl fmt::Display for CommitGraphError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CommitGraphError::MissingRoot => write!(f, "commit graph has no root commit"),
CommitGraphError::MultipleRoots => {
write!(f, "commit graph has multiple root commits")
}
}
}
}

impl Error for CommitGraphError {}

impl CommitGraph {
pub fn new() -> Self {
Self::default()
Expand Down
17 changes: 7 additions & 10 deletions packages/coln-store/src/commit/pst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn encode_store(store: &Store) -> Result<Vec<u8>, CodecError> {
}

/// Decode a store from bytes produced by [`encode_store`].
pub fn decode_store(data: &[u8]) -> Result<Store, Box<StoreIntError>> {
pub fn decode_store(data: &[u8]) -> Result<Store, StoreIntError> {
let encoded = read_store_envelope(data)?;
decode_store_chunks(encoded.next_oid, encoded.chunks)
}
Expand Down Expand Up @@ -89,10 +89,7 @@ fn write_commit_chunk(buf: &mut Vec<u8>, commit: &Commit<'_>) {
Chunk::from(commit).write(buf)
}

fn decode_store_chunks(
next_oid: TableOid,
chunks: Vec<Chunk>,
) -> Result<Store, Box<StoreIntError>> {
fn decode_store_chunks(next_oid: TableOid, chunks: Vec<Chunk>) -> Result<Store, StoreIntError> {
let roots = chunks
.iter()
.filter(|chunk| chunk.chunk_type() == ChunkType::Root)
Expand Down Expand Up @@ -193,12 +190,12 @@ mod tests {
.collect()
}

fn is_data_format_error(result: Result<Store, Box<StoreIntError>>) -> bool {
fn is_data_format_error(result: Result<Store, StoreIntError>) -> bool {
matches!(
result,
Err(err)
if matches!(
err.as_ref(),
&err,
StoreIntError::Encode(CodecError::DataFormatError(_))
)
)
Expand All @@ -215,12 +212,12 @@ mod tests {
.expect("encoded store contains a chunk magic")
}

fn is_missing_dep_error(result: Result<Store, Box<StoreIntError>>) -> bool {
fn is_missing_dep_error(result: Result<Store, StoreIntError>) -> bool {
matches!(
result,
Err(err)
if matches!(
err.as_ref(),
&err,
StoreIntError::Commit(crate::store::error::CommitApplyError::MissingDep)
)
)
Expand Down Expand Up @@ -310,7 +307,7 @@ mod tests {

let err = decode_store(&corrupted).expect_err("checksum mismatch");
assert!(matches!(
err.as_ref(),
err,
StoreIntError::Encode(CodecError::ChecksumMismatch)
));
}
Expand Down
10 changes: 2 additions & 8 deletions packages/coln-store/src/repl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum ReplError {
BadValue { column: usize, message: String },
Io(std::io::Error),
Json(serde_json::Error),
Store(Box<StoreIntError>),
Store(StoreIntError),
Persist(CodecError),
}

Expand Down Expand Up @@ -64,12 +64,6 @@ impl From<serde_json::Error> for ReplError {

impl From<StoreIntError> for ReplError {
fn from(value: StoreIntError) -> Self {
Self::Store(Box::new(value))
}
}

impl From<Box<StoreIntError>> for ReplError {
fn from(value: Box<StoreIntError>) -> Self {
Self::Store(value)
}
}
Expand All @@ -82,7 +76,7 @@ impl From<CodecError> for ReplError {

impl From<ValidationError> for ReplError {
fn from(value: ValidationError) -> Self {
Self::Store(Box::new(value.into()))
Self::Store(value.into())
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/coln-store/src/solver/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ use std::{collections::HashSet, fmt};
use crate::ir::{self, Atom, Prop, RuleEntry, Term};

/// Errors raised while lowering an `ir::Rule` into the restricted solver form.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum CompileError {
#[error("unsupported prop {0}")]
UnsupportedProp(String),
#[error("unsupported term")]
UnsupportedTerm,
#[error("invalid var index: {index} var_count {var_count}")]
InvalidVarIndex { index: i64, var_count: usize },
#[error("invalid column index {column}")]
InvalidColumnIndex { column: i64 },
}

Expand Down
127 changes: 19 additions & 108 deletions packages/coln-store/src/store/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,126 +2,37 @@
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

use std::error::Error;
use std::fmt;

use crate::commit::error::CodecError;
use crate::solver::compile::CompileError;
use crate::solver::validate::RuleViolation;
use crate::table::ValidationError;

/// Store integrity error
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum StoreIntError {
Validation(ValidationError),
Law(Box<RuleViolation>),
Compile(CompileError),
Encode(CodecError),
Commit(CommitApplyError),
}

#[derive(Debug)]
#[error(transparent)]
Validation(#[from] ValidationError),
#[error(transparent)]
Law(#[from] Box<RuleViolation>),
#[error(transparent)]
Compile(#[from] CompileError),
#[error(transparent)]
Encode(#[from] CodecError),
#[error(transparent)]
Commit(#[from] CommitApplyError),
}

#[derive(Debug, thiserror::Error)]
pub enum CommitApplyError {
#[error("missing commit dependency")]
MissingDep,
#[error("disconnected commit")]
DisconnectedCommit,
// A commit that should definitely exist but is missing
#[error("missing commit")]
MissingCommit,
#[error("An existing commit has conflict payload")]
ConflictPayload,
#[error("Root commit cannot be applied")]
RootCommit,
}

impl fmt::Display for CommitApplyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CommitApplyError::MissingDep => write!(f, "missing commit dependency"),
CommitApplyError::DisconnectedCommit => write!(f, "disconnected commit"),
CommitApplyError::MissingCommit => write!(f, "missing commit"),
CommitApplyError::ConflictPayload => {
write!(f, "An existing commit has conflict payload")
}
CommitApplyError::RootCommit => write!(f, "Root commit cannot be applied"),
}
}
}

impl Error for CommitApplyError {}

impl fmt::Display for StoreIntError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
StoreIntError::Validation(err) => write!(f, "{err}"),
StoreIntError::Law(err) => write!(f, "{err}"),
StoreIntError::Compile(err) => write!(f, "{err:?}"),
StoreIntError::Encode(err) => write!(f, "{err:?}"),
StoreIntError::Commit(err) => write!(f, "{err}"),
}
}
}

impl Error for StoreIntError {}

impl From<ValidationError> for StoreIntError {
fn from(value: ValidationError) -> Self {
Self::Validation(value)
}
}

impl From<RuleViolation> for StoreIntError {
fn from(value: RuleViolation) -> Self {
Self::Law(Box::new(value))
}
}

impl From<Box<RuleViolation>> for StoreIntError {
fn from(value: Box<RuleViolation>) -> Self {
Self::Law(value)
}
}

impl From<CompileError> for StoreIntError {
fn from(value: CompileError) -> Self {
Self::Compile(value)
}
}

impl From<CommitApplyError> for StoreIntError {
fn from(value: CommitApplyError) -> Self {
Self::Commit(value)
}
}

impl From<CodecError> for Box<StoreIntError> {
fn from(value: CodecError) -> Self {
Box::new(StoreIntError::Encode(value))
}
}

impl From<CommitApplyError> for Box<StoreIntError> {
fn from(value: CommitApplyError) -> Self {
Box::new(StoreIntError::from(value))
}
}

impl From<ValidationError> for Box<StoreIntError> {
fn from(value: ValidationError) -> Self {
Box::new(StoreIntError::from(value))
}
}

impl From<CompileError> for Box<StoreIntError> {
fn from(value: CompileError) -> Self {
Box::new(StoreIntError::from(value))
}
}

impl From<RuleViolation> for Box<StoreIntError> {
fn from(value: RuleViolation) -> Self {
Box::new(StoreIntError::from(value))
}
}

impl From<Box<RuleViolation>> for Box<StoreIntError> {
fn from(value: Box<RuleViolation>) -> Self {
Box::new(StoreIntError::from(value))
}
}
Loading
Loading