Skip to content

Commit

Permalink
feat: add version and timestamp to error logs
Browse files Browse the repository at this point in the history
I opted for not introducing a breaking change. If a user fails and posts an error prior 2.3.1 (which will be the next release hopefully), we will see `<2.3.1` in the db.
  • Loading branch information
bonomat committed May 9, 2024
1 parent 02bd2fb commit 826eeb0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE reported_errors
DROP COLUMN timestamp;
ALTER TABLE reported_errors
DROP COLUMN version;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Your SQL goes here
ALTER TABLE reported_errors
ADD COLUMN timestamp TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE reported_errors
ADD COLUMN version TEXT NOT NULL DEFAULT '<2.3.1';
2 changes: 2 additions & 0 deletions coordinator/src/db/reported_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use xxi_node::commons::ReportedError;
struct NewReportedError {
trader_pubkey: String,
error: String,
version: String,
}

pub(crate) fn insert(conn: &mut PgConnection, error: ReportedError) -> QueryResult<()> {
Expand All @@ -22,6 +23,7 @@ impl From<ReportedError> for NewReportedError {
Self {
trader_pubkey: value.trader_pk.to_string(),
error: value.msg,
version: value.version.unwrap_or("<2.3.1".to_owned()),
}
}
}
2 changes: 2 additions & 0 deletions coordinator/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ diesel::table! {
id -> Int4,
trader_pubkey -> Text,
error -> Text,
timestamp -> Timestamptz,
version -> Text,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/xxi-node/src/commons/reported_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ use serde::Serialize;
pub struct ReportedError {
pub trader_pk: PublicKey,
pub msg: String,
pub version: Option<String>,
}
3 changes: 3 additions & 0 deletions mobile/native/src/report_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::state::get_or_create_tokio_runtime;
use reqwest::Url;

pub fn report_error_to_coordinator<E: ToString>(error: &E) {
let version = env!("CARGO_PKG_VERSION").to_string();

let client = reqwest_client();
let pk = get_node().inner.info.pubkey;

Expand All @@ -23,6 +25,7 @@ pub fn report_error_to_coordinator<E: ToString>(error: &E) {
.json(&xxi_node::commons::ReportedError {
trader_pk: pk,
msg: error_string,
version: Some(version),
})
.send()
.await
Expand Down

0 comments on commit 826eeb0

Please sign in to comment.