Skip to content

Commit

Permalink
chore: log database errors to Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
insertish committed Dec 17, 2024
1 parent 443f374 commit ac731e5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions Dockerfile.useCurrentArch
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ COPY crates/core/presence/Cargo.toml ./crates/core/presence/
COPY crates/core/result/Cargo.toml ./crates/core/result/
COPY crates/services/autumn/Cargo.toml ./crates/services/autumn/
COPY crates/services/january/Cargo.toml ./crates/services/january/
COPY crates/daemons/pushd/Cargo.toml ./crates/daemons/pushd/
RUN sh /tmp/build-image-layer.sh deps

# Build all apps
Expand Down
11 changes: 11 additions & 0 deletions crates/core/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ macro_rules! report_error {
};
}

#[cfg(feature = "report-macros")]
#[macro_export]
macro_rules! capture_internal_error {
( $expr: expr ) => {
$crate::capture_message(
&format!("{:?} ({}:{}:{})", $expr, file!(), line!(), column!()),
$crate::Level::Error,
);
};
}

#[cfg(feature = "report-macros")]
#[macro_export]
macro_rules! report_internal_error {
Expand Down
20 changes: 20 additions & 0 deletions crates/core/database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ pub use mongodb;
#[macro_use]
extern crate bson;

#[macro_export]
#[cfg(debug_assertions)]
macro_rules! query {
( $self: ident, $type: ident, $collection: expr, $($rest:expr),+ ) => {
Ok($self.$type($collection, $($rest),+).await.unwrap())
};
}

#[macro_export]
#[cfg(not(debug_assertions))]
macro_rules! query {
( $self: ident, $type: ident, $collection: expr, $($rest:expr),+ ) => {
$self.$type($collection, $($rest),+).await
.map_err(|err| {
revolt_config::capture_internal_error!(err);
create_database_error!(stringify!($type), $collection)
})
};
}

macro_rules! database_derived {
( $( $item:item )+ ) => {
$(
Expand Down
17 changes: 0 additions & 17 deletions crates/core/result/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,6 @@ macro_rules! create_database_error {
};
}

#[macro_export]
#[cfg(debug_assertions)]
macro_rules! query {
( $self: ident, $type: ident, $collection: expr, $($rest:expr),+ ) => {
Ok($self.$type($collection, $($rest),+).await.unwrap())
};
}

#[macro_export]
#[cfg(not(debug_assertions))]
macro_rules! query {
( $self: ident, $type: ident, $collection: expr, $($rest:expr),+ ) => {
$self.$type($collection, $($rest),+).await
.map_err(|_| create_database_error!(stringify!($type), $collection))
};
}

#[cfg(test)]
mod tests {
use crate::ErrorType;
Expand Down

0 comments on commit ac731e5

Please sign in to comment.