8000 chore(dal): Single si_db::Error type, use si_db::* types from dal by jkeiser · Pull Request #6114 · systeminit/si · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore(dal): Single si_db::Error type, use si_db::* types from dal #6114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
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
15 changes: 15 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions lib/dal-test/src/expand_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use dal::{
ChangeSet,
ChangeSetId,
DalContext,
Tenancy,
WorkspacePk,
};
use jwt_simple::{
algorithms::RSAKeyPairLike,
claims::Claims,
prelude::Duration,
};
use si_db::Tenancy;
use si_jwt_public_key::SiJwtClaims;
use tracing_subscriber::{
EnvFilter,
Expand Down Expand Up @@ -45,7 +45,7 @@ pub async fn setup_history_actor_ctx(ctx: &mut DalContext) {
)
.await
.expect("unable to associate user with workspace");
ctx.update_history_actor(dal::HistoryActor::User(user.pk()));
ctx.update_history_actor(si_db::HistoryActor::User(user.pk()));
}

/// This function is used during macro expansion for setting up a [`ChangeSet`] in an integration test.
Expand Down
2 changes: 1 addition & 1 deletion lib/dal-test/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use dal::{
Schema,
SchemaVariant,
SchemaVariantId,
User,
UserPk,
attribute::{
path::AttributePath,
Expand All @@ -43,6 +42,7 @@ use names::{
Name,
};
use si_data_nats::async_nats::jetstream::stream::Stream;
use si_db::User;
use tokio::time::Instant;

mod change_set;
Expand Down
10 changes: 6 additions & 4 deletions lib/dal-test/src/signup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
use dal::{
ChangeSet,
DalContext,
HistoryActor,
HistoryEvent,
KeyPair,
Tenancy,
User,
UserPk,
Workspace,
WorkspacePk,
Expand All @@ -24,6 +20,12 @@ use serde::{
Deserialize,
Serialize,
};
use si_db::{
HistoryActor,
HistoryEvent,
Tenancy,
User,
};

/// A wrapper for creating [`Workspaces`](Workspace) for integration tests.
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
Expand Down
1 change: 1 addition & 0 deletions lib/dal/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ rust_test(
"//lib/dal-test:dal-test",
"//lib/pending-events:pending-events",
"//lib/rebaser-server:rebaser-server",
"//lib/si-db:si-db",
"//lib/si-events-rs:si-events",
"//lib/si-id:si-id",
"//lib/si-frontend-mv-types-rs:si-frontend-mv-types",
Expand Down
9 changes: 5 additions & 4 deletions lib/dal/src/audit_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use crate::{
ChangeSetError,
ChangeSetStatus,
DalContext,
TenancyError,
TransactionsError,
WsEvent,
WsEventResult,
Expand All @@ -54,6 +53,8 @@ pub enum AuditLoggingError {
PendingEventsError(#[from] PendingEventsError),
#[error("shuttle error: {0}")]
Shuttle(#[from] ShuttleError),
#[error("si db error: {0}")]
SiDb(#[from] si_db::Error),
#[error("transactions error: {0}")]
Transactions(#[from] Box<TransactionsError>),
}
Expand All @@ -80,7 +81,7 @@ 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(TransactionsError::SiDb(si_db::Error::NoWorkspace)) => return Ok(()),
Err(err) => return Err(AuditLoggingError::Transactions(Box::new(err))),
};

Expand Down Expand Up @@ -216,7 +217,7 @@ 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(TransactionsError::SiDb(si_db::Error::NoWorkspace)) => return Ok(()),
Err(err) => return Err(AuditLoggingError::Transactions(Box::new(err))),
};

Expand Down Expand Up @@ -247,7 +248,7 @@ 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(TransactionsError::SiDb(si_db::Error::NoWorkspace)) => return Ok(()),
Err(err) => return Err(AuditLoggingError::Transactions(Box::new(err))),
};

Expand Down
2 changes: 1 addition & 1 deletion lib/dal/src/cached_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use si_data_pg::{
PgError,
PgRow,
};
use si_db::HistoryActor;
pub use si_id::CachedModuleId;
use si_id::UserPk;
use si_pkg::{
Expand All @@ -42,7 +43,6 @@ use ulid::Ulid;
use crate::{
ComponentType,
DalContext,
HistoryActor,
SchemaId,
TransactionsError,
slow_rt::{
Expand Down
44 changes: 18 additions & 26 deletions lib/dal/src/change_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ use si_data_pg::{
PgError,
PgRow,
};
use si_db::change_set::FIND_ANCESTORS_QUERY;
use si_db::{
HistoryActor,
HistoryEvent,
User,
change_set::FIND_ANCESTORS_QUERY,
};
use si_events::{
RebaseBatchAddressKind,
WorkspaceSnapshotAddress,
Expand All @@ -26,7 +31,12 @@ use si_events::{
ulid::Ulid,
workspace_snapshot::Checksum,
};
use si_id::EntityId;
use si_id::{
ActionId,
EntityId,
UserPk,
WorkspacePk,
};
use si_layer_cache::LayerDbError;
use telemetry::prelude::*;
use thiserror::Error;
Expand All @@ -38,28 +48,18 @@ use crate::{
DalContext,
Func,
FuncError,
HistoryActor,
HistoryEvent,
HistoryEventError,
Schema,
SchemaError,
SchemaVariant,
SchemaVariantError,
TransactionsError,
User,
UserError,
UserPk,
Workspace,
WorkspaceError,
WorkspacePk,
WorkspaceSnapshot,
WorkspaceSnapshotError,
WsEvent,
WsEventError,
action::{
ActionError,
ActionId,
},
action::ActionError,
billing_publish::{
self,
BillingPublishError,
Expand Down Expand Up @@ -101,8 +101,6 @@ pub enum ChangeSetError {
EnumParse(#[from] strum::ParseError),
#[error("func error: {0}")]
Func(#[from] Box<FuncError>),
#[error("history event error: {0}")]
HistoryEvent(#[from] HistoryEventError),
#[error("invalid user actor pk")]
InvalidActor(UserPk),
#[error("invalid user system init")]
Expand Down Expand Up @@ -133,6 +131,8 @@ pub enum ChangeSetError {
SchemaVariant(#[from] Box<SchemaVariantError>),
#[error("serde json error: {0}")]
SerdeJson(#[from] serde_json::Error),
#[error("si db error: {0}")]
SiDb(#[from] si_db::Error),
#[error("slow runtime error: {0}")]
SlowRuntime(#[from] SlowRuntimeError),
#[error("transactions error: {0}")]
Expand All @@ -143,8 +143,6 @@ pub enum ChangeSetError {
"found an unexpected number of open change sets matching default change set (should be one, found {0:?})"
)]
UnexpectedNumberOfOpenChangeSetsMatchingDefaultChangeSet(Vec<ChangeSetId>),
#[error("user error: {0}")]
User(#[from] UserError),
#[error("workspace error: {0}")]
Workspace(#[from] Box<WorkspaceError>),
#[error("workspace snapshot error: {0}")]
Expand Down Expand Up @@ -186,10 +184,10 @@ pub enum ChangeSetApplyError {
InvalidUserSystemInit,
#[error("change set ({0}) does not have a base change set")]
NoBaseChangeSet(ChangeSetId),
#[error("si db error: {0}")]
SiDb(#[from] si_db::Error),
#[error("transactions error: {0}")]
Transactions(#[from] TransactionsError),
#[error("user error: {0}")]
User(#[from] UserError),
}

/// A superset of [`ChangeSetResult`] used when performing apply logic.
Expand Down Expand Up @@ -1089,13 +1087,7 @@ impl ChangeSet {
}
pub async fn extract_userid_from_context_or_error(ctx: &DalContext) -> ChangeSetResult<UserPk> {
let user_id = match ctx.history_actor() {
HistoryActor::User(user_pk) => {
let maybe_user = User::get_by_pk(ctx, *user_pk).await;
match maybe_user {
Ok(user) => user.pk(),
Err(err) => return Err(ChangeSetError::User(err)),
}
}
HistoryActor::User(user_pk) => User::get_by_pk(ctx, *user_pk).await?.pk(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

HistoryActor::SystemInit => return Err(ChangeSetError::InvalidUserSystemInit),
};
Ok(user_id)
Expand Down
2 changes: 1 addition & 1 deletion lib/dal/src/change_set/approval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use si_data_pg::{
PgError,
PgRow,
};
use si_db::HistoryActor;
pub use si_events::ChangeSetApprovalStatus;
use si_events::merkle_tree_hash::MerkleTreeHash;
use si_id::{
Expand All @@ -54,7 +55,6 @@ use super::{
};
use crate::{
DalContext,
HistoryActor,
TransactionsError,
WorkspaceSnapshotError,
};
Expand Down
Loading
0