Skip to content
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

Improve client error messages #512

Merged
merged 4 commits into from
Nov 30, 2021
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
6 changes: 3 additions & 3 deletions identity-iota/src/chain/integration_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ impl IntegrationChain {
let root_document: IotaDocument = {
let valid_root_documents: Vec<IotaDocument> = index
.remove(&MessageId::null())
.ok_or(Error::DIDNotFound("DID not found or pruned"))?
.ok_or_else(|| Error::DIDNotFound("DID not found or pruned".to_owned()))?
.into_iter()
.filter(|doc| IotaDocument::verify_root_document(doc).is_ok())
.collect();

if valid_root_documents.is_empty() {
return Err(Error::DIDNotFound("no valid root document found"));
return Err(Error::DIDNotFound("no valid root document found".to_owned()));
}

let sorted_root_documents: Vec<IotaDocument> = sort_by_milestone(valid_root_documents, client).await?;
sorted_root_documents
.into_iter()
.next()
.ok_or(Error::DIDNotFound("no root document confirmed by a milestone found"))?
.ok_or_else(|| Error::DIDNotFound("no root document confirmed by a milestone found".to_owned()))?
};

// Construct the rest of the integration chain.
Expand Down
15 changes: 3 additions & 12 deletions identity-iota/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ pub enum Error {
ClientError(#[from] iota_client::error::Error),
#[error("Invalid Message: {0}")]
InvalidMessage(#[from] iota_client::bee_message::Error),

#[error("{0}")]
DIDNotFound(&'static str),
DIDNotFound(String),
#[error("Invalid Document - Missing Message Id")]
InvalidDocumentMessageId,
#[error("Invalid Document - Signing Verification Method Type Not Supported")]
Expand All @@ -31,16 +32,6 @@ pub enum Error {
InvalidRootDocument,
#[error("Invalid Network Name")]
InvalidNetworkName,
#[error("Invalid Tryte Conversion")]
InvalidTryteConversion,
#[error("Invalid Transaction Bundle")]
InvalidTransactionBundle,
#[error("Invalid Transaction Hashes")]
InvalidTransactionHashes,
#[error("Invalid Transaction Trytes")]
InvalidTransactionTrytes,
#[error("Invalid Bundle Tail")]
InvalidBundleTail,
#[error("Invalid Presentation Holder")]
InvalidPresentationHolder,
#[error("Chain Error: {error}")]
Expand All @@ -49,7 +40,7 @@ pub enum Error {
MissingSigningKey,
#[error("Cannot Revoke Verification Method")]
CannotRevokeMethod,
#[error("No Client Nodes Provided")]
#[error("no client nodes provided for network")]
NoClientNodesProvided,
#[error("No Explorer URL Set")]
NoExplorerURLSet,
Expand Down
10 changes: 9 additions & 1 deletion identity-iota/src/tangle/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::did::IotaDID;
use crate::document::DiffMessage;
use crate::document::IotaDocument;
use crate::error::Error;
use crate::error::Error::DIDNotFound;
use crate::error::Result;
use crate::tangle::ClientBuilder;
use crate::tangle::DIDMessageEncoding;
Expand Down Expand Up @@ -155,9 +156,16 @@ impl Client {
/// Fetches a [`DocumentChain`] given an [`IotaDID`].
pub async fn read_document_chain(&self, did: &IotaDID) -> Result<DocumentChain> {
log::trace!("Read Document Chain: {}", did);
log::trace!("Integration Chain Address: {}", did.tag());
if self.network != did.network()? {
return Err(DIDNotFound(format!(
"DID network '{}' does not match client network '{}'",
did.network_str(),
self.network.name_str()
)));
}

// Fetch all messages for the integration chain.
log::trace!("Integration Chain Address: {}", did.tag());
let messages: Vec<Message> = self.read_messages(did.tag()).await?;
let integration_chain: IntegrationChain = IntegrationChain::try_from_messages(did, &messages, self).await?;

Expand Down