Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Add backtrace to CoreError
Browse files Browse the repository at this point in the history
closes #395
  • Loading branch information
maackle committed Mar 12, 2020
1 parent 6a72b1a commit ce89558
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/core_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository = "https://github.com/holochain/holochain-rust"
futures = "=0.3.2"
arrayref = "=0.3.5"
base64 = "=0.10.1"
backtrace = "=0.3.27"
backtrace = { version = "=0.3.27", features = [ "serialize-serde" ] }
chrono = "=0.4.6"
serde = "=1.0.104"
serde_derive = "=1.0.104"
Expand Down
13 changes: 8 additions & 5 deletions crates/core_types/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use holochain_locksmith::LocksmithError;
use holochain_persistence_api::{error::PersistenceError, hash::HashString};
use lib3h_crypto_api::CryptoError;

use backtrace::Backtrace;
use serde_json::Error as SerdeError;
use std::{
error::Error,
Expand All @@ -32,13 +33,12 @@ use std::{
/// and back to the Holochain Instance via wasm memory.
/// Follows the Error + ErrorKind pattern
/// Holds extra debugging info for indicating where in code ther error occured.
#[derive(Clone, Debug, Serialize, Deserialize, DefaultJson, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, Serialize, Deserialize, DefaultJson)]
pub struct CoreError {
pub kind: HolochainError,
pub file: String,
pub line: String,
// TODO #395 - Add advance error debugging info
// pub stack_trace: Backtrace
pub backtrace: Backtrace,
}

// Error trait by using the inner Error
Expand All @@ -54,6 +54,7 @@ impl CoreError {
kind: hc_err,
file: String::new(),
line: String::new(),
backtrace: Backtrace::new(),
}
}
}
Expand All @@ -80,8 +81,8 @@ impl fmt::Display for CoreError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Holochain Core error: {}\n --> {}:{}\n",
self.kind, self.file, self.line,
"Holochain Core error: {}\n --> {}:{}\nbacktrace: {:?}",
self.kind, self.file, self.line, self.backtrace
)
}
}
Expand Down Expand Up @@ -435,6 +436,7 @@ mod tests {
kind: error.clone(),
file: file!().to_string(),
line: line!().to_string(),
backtrace: Backtrace::new(),
};

assert_ne!(
Expand All @@ -443,6 +445,7 @@ mod tests {
kind: error,
file: file!().to_string(),
line: line!().to_string(),
backtrace: Backtrace::new(),
}
.to_string(),
);
Expand Down

0 comments on commit ce89558

Please sign in to comment.