Get rid of anyhow.

This commit is contained in:
James Pace 2026-07-03 14:33:40 -04:00
parent 1b2411436d
commit 766cd48c1a
5 changed files with 107 additions and 34 deletions

63
Cargo.lock generated
View File

@ -2,20 +2,69 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "anyhow"
version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
[[package]] [[package]]
name = "j7s_diagnostics" name = "j7s_diagnostics"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow",
"limbo_graph", "limbo_graph",
"thiserror",
] ]
[[package]] [[package]]
name = "limbo_graph" name = "limbo_graph"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "proc-macro2"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "2.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"

View File

@ -4,5 +4,5 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
anyhow = { version = "1.0", default-features = false }
limbo_graph = { path = "../limbo_graph" } limbo_graph = { path = "../limbo_graph" }
thiserror = { version = "2.0.18", default-features = false }

View File

@ -9,7 +9,7 @@
// defined by the Mozilla Public License, v. 2.0. // defined by the Mozilla Public License, v. 2.0.
// //
use crate::DiagnosticStatus; use crate::DiagnosticStatus;
use anyhow::anyhow; use crate::error::{Error, Result};
#[derive(Clone)] #[derive(Clone)]
pub enum DiagnosticNode { pub enum DiagnosticNode {
@ -30,10 +30,10 @@ impl DiagnosticNode {
} }
} }
pub fn value(&self) -> anyhow::Result<&DiagnosticStatus> { pub fn value(&self) -> Result<&DiagnosticStatus> {
match self { match self {
Self::DiagnosticStatus(value) => Ok(value), Self::DiagnosticStatus(value) => Ok(value),
_ => Err(anyhow!("Can't get value of root key.")), _ => Err(Error::from_msg("Can't get value of root key.")),
} }
} }
} }

28
src/error.rs Normal file
View File

@ -0,0 +1,28 @@
//
// Copyright 2026 James Pace
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, v. 2.0.
//
use alloc::string::{String, ToString};
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("GraphError: {0}")]
GraphError(#[from] limbo_graph::Error),
#[error("Error from j7s_diagnostics: {0}")]
Msg(String),
}
impl Error {
pub fn from_msg(msg: &str) -> Self {
Error::Msg(msg.to_string())
}
}
pub type Result<T, E = Error> = core::result::Result<T, E>;

View File

@ -9,25 +9,24 @@
// defined by the Mozilla Public License, v. 2.0. // defined by the Mozilla Public License, v. 2.0.
// //
// TODO: Remove anyhow.
#![no_std] #![no_std]
#![allow(unused_imports)] #![allow(unused_imports)]
extern crate alloc; extern crate alloc;
mod diagnostic_node; mod diagnostic_node;
mod diagnostic_status; mod diagnostic_status;
mod error;
mod name_parsing; mod name_parsing;
use anyhow::anyhow;
use crate::alloc::string::ToString;
use alloc::borrow::ToOwned; use alloc::borrow::ToOwned;
use alloc::collections::BTreeMap; use alloc::collections::BTreeMap;
use alloc::collections::VecDeque; use alloc::collections::VecDeque;
use alloc::string::String; use alloc::string::String;
use alloc::string::ToString;
use alloc::vec::Vec; use alloc::vec::Vec;
pub use crate::diagnostic_status::*; pub use crate::diagnostic_status::*;
pub use crate::error::*;
use crate::diagnostic_node::*; use crate::diagnostic_node::*;
use crate::name_parsing::*; use crate::name_parsing::*;
@ -47,13 +46,13 @@ impl DiagnosticGraph {
return self.graph.root_key(); return self.graph.root_key();
} }
pub fn value_of(&self, key: &limbo_graph::Key) -> anyhow::Result<DiagnosticStatus> { pub fn value_of(&self, key: &limbo_graph::Key) -> Result<DiagnosticStatus> {
let graph_value = self.graph.value_of(key)?; let graph_value = self.graph.value_of(key)?;
let result = graph_value.value()?; let result = graph_value.value()?;
Ok(result.clone()) Ok(result.clone())
} }
pub fn children_of(&self, key: &limbo_graph::Key) -> anyhow::Result<Vec<limbo_graph::Key>> { pub fn children_of(&self, key: &limbo_graph::Key) -> Result<Vec<limbo_graph::Key>> {
let result = self.graph.children_of(key)?; let result = self.graph.children_of(key)?;
Ok(result) Ok(result)
} }
@ -62,9 +61,9 @@ impl DiagnosticGraph {
&self, &self,
parent: &limbo_graph::Key, parent: &limbo_graph::Key,
desired_child_name: &str, desired_child_name: &str,
) -> anyhow::Result<Option<limbo_graph::Key>> { ) -> Result<Option<limbo_graph::Key>> {
if !name_is_basic(&desired_child_name.to_owned()) { if !name_is_basic(&desired_child_name.to_owned()) {
return Err(anyhow!("desired child name must be basic.")); return Err(Error::from_msg("desired child name must be basic."));
} }
let all_children = self.children_of(parent)?; let all_children = self.children_of(parent)?;
for child in all_children.iter() { for child in all_children.iter() {
@ -76,10 +75,7 @@ impl DiagnosticGraph {
return Ok(None); return Ok(None);
} }
pub fn key_from_full_name( pub fn key_from_full_name(&self, full_name: &String) -> Result<Option<limbo_graph::Key>> {
&self,
full_name: &String,
) -> anyhow::Result<Option<limbo_graph::Key>> {
let name_as_vec = split_name(&full_name); let name_as_vec = split_name(&full_name);
let mut cur_base_key = self.graph.root_key(); let mut cur_base_key = self.graph.root_key();
@ -94,7 +90,7 @@ impl DiagnosticGraph {
return Ok(Some(cur_base_key)); return Ok(Some(cur_base_key));
} }
pub fn full_name_from_key(&self, key: &limbo_graph::Key) -> anyhow::Result<String> { pub fn full_name_from_key(&self, key: &limbo_graph::Key) -> Result<String> {
let path_to_key = self.graph.backtrack_from_key(key)?; let path_to_key = self.graph.backtrack_from_key(key)?;
let mut full_name = String::new(); let mut full_name = String::new();
@ -112,7 +108,7 @@ impl DiagnosticGraph {
pub fn value_from_name( pub fn value_from_name(
&self, &self,
full_name: &String, full_name: &String,
) -> anyhow::Result<Option<(DiagnosticStatus, limbo_graph::Key)>> { ) -> Result<Option<(DiagnosticStatus, limbo_graph::Key)>> {
let key = self.key_from_full_name(full_name)?; let key = self.key_from_full_name(full_name)?;
if key.is_none() { if key.is_none() {
return Ok(None); return Ok(None);
@ -123,7 +119,7 @@ impl DiagnosticGraph {
return Ok(Some((value, key))); return Ok(Some((value, key)));
} }
pub fn add_status(&mut self, status: DiagnosticStatus) -> anyhow::Result<()> { pub fn add_status(&mut self, status: DiagnosticStatus) -> Result<()> {
// If I'm basic I just need to be added as a child of the root. // If I'm basic I just need to be added as a child of the root.
if status.name_is_basic() { if status.name_is_basic() {
self.graph.add( self.graph.add(
@ -154,7 +150,7 @@ impl DiagnosticGraph {
let child_node = self.graph.value_of(&child)?; let child_node = self.graph.value_of(&child)?;
if child_node.is_root() { if child_node.is_root() {
// A child node can't be root. // A child node can't be root.
return Err(anyhow!("A child node can't be root!")); return Err(Error::from_msg("A child node can't be root!"));
} }
if child_node.value()?.name() == *parent_name { if child_node.value()?.name() == *parent_name {
// The child node matched the parent we were looking for. // The child node matched the parent we were looking for.
@ -195,14 +191,14 @@ impl DiagnosticGraph {
Ok(()) Ok(())
} }
pub fn add_status_vec(&mut self, statuses: &Vec<DiagnosticStatus>) -> anyhow::Result<()> { pub fn add_status_vec(&mut self, statuses: &Vec<DiagnosticStatus>) -> Result<()> {
for status in statuses { for status in statuses {
self.add_status(status.clone())?; self.add_status(status.clone())?;
} }
Ok(()) Ok(())
} }
pub fn reconcile_levels(&mut self) -> anyhow::Result<()> { pub fn reconcile_levels(&mut self) -> Result<()> {
let leaf_keys = self.graph.find_leaf_keys()?; let leaf_keys = self.graph.find_leaf_keys()?;
'leaf_key_loop: for leaf_key in leaf_keys.iter() { 'leaf_key_loop: for leaf_key in leaf_keys.iter() {
@ -238,7 +234,7 @@ impl DiagnosticGraph {
Ok(()) Ok(())
} }
pub fn export_graph(&self) -> anyhow::Result<Vec<DiagnosticStatus>> { pub fn export_graph(&self) -> Result<Vec<DiagnosticStatus>> {
let keys_in_order = self.graph.get_keys_by_depth()?; let keys_in_order = self.graph.get_keys_by_depth()?;
let mut statuses = Vec::<DiagnosticStatus>::new(); let mut statuses = Vec::<DiagnosticStatus>::new();
@ -288,7 +284,7 @@ mod tests {
} }
#[test] #[test]
fn add_one_to_graph() -> anyhow::Result<()> { fn add_one_to_graph() -> Result<()> {
let mut graph = DiagnosticGraph::new(); let mut graph = DiagnosticGraph::new();
graph.add_status(make_a_status_with_name("/a/b/c"))?; graph.add_status(make_a_status_with_name("/a/b/c"))?;
@ -315,7 +311,7 @@ mod tests {
} }
#[test] #[test]
fn add_multiple_to_graph() -> anyhow::Result<()> { fn add_multiple_to_graph() -> Result<()> {
let statuses = vec![ let statuses = vec![
make_a_status_with_name("/a"), make_a_status_with_name("/a"),
make_a_status_with_name("/a/b"), make_a_status_with_name("/a/b"),
@ -354,7 +350,7 @@ mod tests {
} }
#[test] #[test]
fn key_name_connections() -> anyhow::Result<()> { fn key_name_connections() -> Result<()> {
let statuses = vec![ let statuses = vec![
make_a_status_with_name("/a"), make_a_status_with_name("/a"),
make_a_status_with_name("/a/b"), make_a_status_with_name("/a/b"),
@ -381,7 +377,7 @@ mod tests {
} }
#[test] #[test]
fn reconcile_graph() -> anyhow::Result<()> { fn reconcile_graph() -> Result<()> {
let statuses = vec![ let statuses = vec![
make_a_status_with_name_and_level("/a", DiagnosticLevel::UNSET), make_a_status_with_name_and_level("/a", DiagnosticLevel::UNSET),
make_a_status_with_name_and_level("/a/b", DiagnosticLevel::UNSET), make_a_status_with_name_and_level("/a/b", DiagnosticLevel::UNSET),