Skip to content

Commit

Permalink
wip: What if we had a little anyhow? As a treat.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelwig committed Dec 17, 2024
1 parent 68eca14 commit 1832d3b
Show file tree
Hide file tree
Showing 59 changed files with 462 additions and 528 deletions.
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.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ rust-version = "1.82"
publish = false

[workspace.dependencies]
anyhow = { version = "1.0.94" }
async-nats = { version = "0.38.0", features = ["service"] }
async-openai = "0.26.0"
async-recursion = "1.1.1"
Expand All @@ -105,7 +106,12 @@ bollard = "0.18.1"
bytes = "1.9.0"
chrono = { version = "0.4.39", features = ["serde"] }
ciborium = "0.2.2"
clap = { version = "4.5.23", features = ["derive", "color", "env", "wrap_help"] }
clap = { version = "4.5.23", features = [
"derive",
"color",
"env",
"wrap_help",
] }
color-eyre = "0.6.3"
config = { version = "0.14.1", default-features = false, features = ["toml"] }
convert_case = "0.6.0"
Expand Down
1 change: 1 addition & 0 deletions lib/dal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ telemetry-nats = { path = "../../lib/telemetry-nats-rs" }
telemetry-utils = { path = "../../lib/telemetry-utils-rs" }
veritech-client = { path = "../../lib/veritech-client" }

anyhow = { workspace = true }
async-recursion = { workspace = true }
async-trait = { workspace = true }
base64 = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions lib/dal/src/action.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::{HashSet, VecDeque};

use anyhow::Result;
use petgraph::prelude::*;
use postgres_types::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -63,7 +64,7 @@ pub enum ActionError {
WsEvent(#[from] WsEventError),
}

pub type ActionResult<T> = Result<T, ActionError>;
pub type ActionResult<T> = Result<T>;

pub use si_id::ActionId;
pub use si_id::ActionPrototypeId;
Expand Down Expand Up @@ -448,7 +449,7 @@ impl Action {
}
}

Err(ActionError::PrototypeNotFoundForAction(action_id))
Err(ActionError::PrototypeNotFoundForAction(action_id).into())
}

pub async fn component_id(
Expand Down
3 changes: 2 additions & 1 deletion lib/dal/src/action/prototype.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use anyhow::Result;
use petgraph::{Direction::Incoming, Outgoing};
use serde::{Deserialize, Serialize};
use si_events::{ActionResultState, FuncRunId};
Expand Down Expand Up @@ -66,7 +67,7 @@ pub enum ActionPrototypeError {
WsEvent(#[from] WsEventError),
}

pub type ActionPrototypeResult<T> = Result<T, ActionPrototypeError>;
pub type ActionPrototypeResult<T> = Result<T>;

#[remain::sorted]
#[derive(Debug, Copy, Clone, Deserialize, Serialize, PartialEq, Eq, Display, Hash)]
Expand Down
12 changes: 5 additions & 7 deletions lib/dal/src/actor_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![warn(missing_docs, clippy::missing_errors_doc, clippy::missing_panics_doc)]

use anyhow::Result;
use serde::{Deserialize, Serialize};

use crate::{DalContext, HistoryActor, StandardModelError, User, UserPk};
Expand Down Expand Up @@ -42,15 +43,12 @@ impl ActorView {
///
/// Returns [`Err`] if a user cannot be determined given a user pk or if there is a aconnection
/// issue with the database.
pub async fn from_history_actor(
ctx: &DalContext,
history_actor: HistoryActor,
) -> Result<Self, StandardModelError> {
pub async fn from_history_actor(ctx: &DalContext, history_actor: HistoryActor) -> Result<Self> {
match history_actor {
HistoryActor::User(user_pk) => {
let user = User::get_by_pk(ctx, user_pk)
.await?
.ok_or(StandardModelError::UserNotFound(user_pk))?;
.ok_or_else(|| StandardModelError::UserNotFound(user_pk))?;
Ok(Self::User {
pk: user.pk(),
label: user.name().to_string(),
Expand All @@ -69,7 +67,7 @@ impl postgres_types::ToSql for ActorView {
&self,
ty: &postgres_types::Type,
out: &mut postgres_types::private::BytesMut,
) -> Result<postgres_types::IsNull, Box<dyn std::error::Error + Sync + Send>>
) -> std::result::Result<postgres_types::IsNull, Box<dyn std::error::Error + Sync + Send>>
where
Self: Sized,
{
Expand All @@ -88,7 +86,7 @@ impl postgres_types::ToSql for ActorView {
&self,
ty: &postgres_types::Type,
out: &mut postgres_types::private::BytesMut,
) -> Result<postgres_types::IsNull, Box<dyn std::error::Error + Sync + Send>> {
) -> std::result::Result<postgres_types::IsNull, Box<dyn std::error::Error + Sync + Send>> {
let json = serde_json::to_value(self)?;
postgres_types::ToSql::to_sql(&json, ty, out)
}
Expand Down
3 changes: 2 additions & 1 deletion lib/dal/src/attribute/prototype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use std::sync::Arc;

use anyhow::Result;
use content_node_weight::ContentNodeWeight;
use petgraph::Direction;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -84,7 +85,7 @@ pub enum AttributePrototypeError {
WorkspaceSnapshot(#[from] WorkspaceSnapshotError),
}

pub type AttributePrototypeResult<T> = Result<T, AttributePrototypeError>;
pub type AttributePrototypeResult<T> = Result<T>;

/// Indicates the _one and only one_ eventual parent of a corresponding [`AttributePrototype`].
///
Expand Down
3 changes: 2 additions & 1 deletion lib/dal/src/attribute/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use std::collections::{HashMap, HashSet, VecDeque};
use std::sync::Arc;

use anyhow::Result;
use async_recursion::async_recursion;
use indexmap::IndexMap;
use petgraph::prelude::*;
Expand Down Expand Up @@ -230,7 +231,7 @@ impl From<ComponentError> for AttributeValueError {
}
}

pub type AttributeValueResult<T> = Result<T, AttributeValueError>;
pub type AttributeValueResult<T> = Result<T>;

pub use si_id::AttributeValueId;

Expand Down
35 changes: 17 additions & 18 deletions lib/dal/src/audit_logging.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! This module provides audit logging functionality to the rest of the crate.
use anyhow::Result;
use audit_database::AuditDatabaseContext;
use audit_database::AuditDatabaseError;
use audit_database::AuditLogRow;
Expand Down Expand Up @@ -44,7 +45,7 @@ pub enum AuditLoggingError {
Transactions(#[from] Box<TransactionsError>),
}

type Result<T> = std::result::Result<T, AuditLoggingError>;
// type Result<T> = std::result::Result<T, AuditLoggingError>;

/// Publishes all pending [`AuditLogs`](AuditLog) to the audit logs stream for the event session.
///
Expand All @@ -66,8 +67,10 @@ pub(crate) async fn publish_pending(
// TODO(nick): nuke this from intergalactic orbit. Then do it again.
let workspace_id = match ctx.workspace_pk() {
Ok(workspace_id) => workspace_id,
Err(TransactionsError::Tenancy(TenancyError::NoWorkspace)) => return Ok(()),
Err(err) => return Err(AuditLoggingError::Transactions(Box::new(err))),
Err(error) => match error.downcast_ref::<TenancyError>() {
Some(TenancyError::NoWorkspace) => return Ok(()),
_ => return Err(error),
},
};

let (tracker, provided_tracker) = match tracker {
Expand Down Expand Up @@ -203,8 +206,10 @@ pub(crate) async fn write(
// TODO(nick): nuke this from intergalactic orbit. Then do it again.
let workspace_id = match ctx.workspace_pk() {
Ok(workspace_id) => workspace_id,
Err(TransactionsError::Tenancy(TenancyError::NoWorkspace)) => return Ok(()),
Err(err) => return Err(AuditLoggingError::Transactions(Box::new(err))),
Err(error) => match error.downcast_ref::<TenancyError>() {
Some(TenancyError::NoWorkspace) => return Ok(()),
_ => return Err(error),
},
};

let destination_change_set_id =
Expand Down Expand Up @@ -233,8 +238,10 @@ pub(crate) async fn write_final_message(ctx: &DalContext) -> Result<()> {
// TODO(nick): nuke this from intergalactic orbit. Then do it again.
let workspace_id = match ctx.workspace_pk() {
Ok(workspace_id) => workspace_id,
Err(TransactionsError::Tenancy(TenancyError::NoWorkspace)) => return Ok(()),
Err(err) => return Err(AuditLoggingError::Transactions(Box::new(err))),
Err(error) => match error.downcast_ref::<TenancyError>() {
Some(TenancyError::NoWorkspace) => return Ok(()),
_ => return Err(error),
},
};

let pending_events_stream = PendingEventsStream::get_or_create(ctx.jetstream_context()).await?;
Expand All @@ -251,25 +258,17 @@ pub async fn list(
size: usize,
sort_ascending: bool,
) -> Result<(Vec<AuditLogRow>, bool)> {
let workspace_id = ctx.workspace_pk().map_err(Box::new)?;
let workspace_id = ctx.workspace_pk()?;
let change_set_id = ctx.change_set_id();

let change_set_ids = {
let mut change_set_ids = vec![change_set_id];
if ctx
.get_workspace_default_change_set_id()
.await
.map_err(Box::new)?
== change_set_id
{
if ctx.get_workspace_default_change_set_id().await? == change_set_id {
// NOTE(nick,fletcher,brit,paul): we need to decide what this entails on HEAD in the long term. For now,
// it is all non-open, non-abandoned change sets... which are just the applied ones. In the future, we may
// or will need to ability to tell a story about abandoned change sets. This is for future us or future
// victims to solve. Good luck!
for applied_change_set in ChangeSet::list_all_applied(ctx, workspace_id)
.await
.map_err(Box::new)?
{
for applied_change_set in ChangeSet::list_all_applied(ctx, workspace_id).await? {
change_set_ids.push(applied_change_set.id);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/dal/src/billing_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
while_true
)]

use anyhow::Result;
use billing_events::{BillingEvent, BillingEventKind, BillingEventsError};
use chrono::Utc;
use si_events::FuncRunId;
Expand Down Expand Up @@ -55,7 +56,7 @@ pub enum BillingPublishError {
Transactions(#[from] TransactionsError),
}

type BillingPublishResult<T> = Result<T, BillingPublishError>;
type BillingPublishResult<T> = Result<T>;

#[instrument(
name = "billing_publish.for_head_change_set_pointer_update",
Expand Down
5 changes: 3 additions & 2 deletions lib/dal/src/cached_module.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{collections::HashMap, str::FromStr, sync::Arc};

use anyhow::Result;
use chrono::{DateTime, Utc};
use itertools::Itertools;
use postgres_types::ToSql;
Expand Down Expand Up @@ -44,7 +45,7 @@ pub enum CachedModuleError {
UrlParse(#[from] url::ParseError),
}

pub type CachedModuleResult<T> = Result<T, CachedModuleError>;
pub type CachedModuleResult<T> = Result<T>;

#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -119,7 +120,7 @@ impl CachedModule {
}

let Some(package_data) = &self.package_data else {
return Err(CachedModuleError::NoPackageData);
return Err(CachedModuleError::NoPackageData.into());
};

Ok(package_data.as_slice())
Expand Down
Loading

0 comments on commit 1832d3b

Please sign in to comment.