Skip to content

Commit

Permalink
Merge branch 'master' into refactor-diagnosis
Browse files Browse the repository at this point in the history
  • Loading branch information
ericswanson-dfinity authored Jun 27, 2023
2 parents 94730cb + 2dda99a commit 5ba396f
Show file tree
Hide file tree
Showing 39 changed files with 437 additions and 376 deletions.
300 changes: 229 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ license = "Apache-2.0"

[workspace.dependencies]
candid = "0.8.4"
ic-agent = "0.23.1"
ic-agent = "0.24.1"
ic-asset = { path = "src/canisters/frontend/ic-asset" }
ic-cdk = "0.8.0"
ic-cdk-macros = "0.6.7"
ic-identity-hsm = "0.23.1"
ic-utils = "0.23.1"
ic-identity-hsm = "0.24.1"
ic-utils = "0.24.1"

aes-gcm = "0.9.4"
anyhow = "1.0.56"
Expand Down Expand Up @@ -68,19 +68,19 @@ url = "2.1.0"
walkdir = "2.3.2"

[patch.crates-io.ic-agent]
version = "0.23.2"
version = "0.24.1"
git = "https://github.com/dfinity/agent-rs.git"
rev = "862ddb2871db426d0e42e816a2f792d224d7bdf5"
rev = "b9c57f8bab23cc9936dca4560293ffe485471c6d"

[patch.crates-io.ic-identity-hsm]
version = "0.23.2"
version = "0.24.1"
git = "https://github.com/dfinity/agent-rs.git"
rev = "862ddb2871db426d0e42e816a2f792d224d7bdf5"
rev = "b9c57f8bab23cc9936dca4560293ffe485471c6d"

[patch.crates-io.ic-utils]
version = "0.23.2"
version = "0.24.1"
git = "https://github.com/dfinity/agent-rs.git"
rev = "862ddb2871db426d0e42e816a2f792d224d7bdf5"
rev = "b9c57f8bab23cc9936dca4560293ffe485471c6d"

[profile.release]
panic = 'abort'
Expand Down
10 changes: 5 additions & 5 deletions src/canisters/frontend/ic-asset/src/asset/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error::get_asset_config::GetAssetConfigError;
use crate::error::get_asset_config::GetAssetConfigError::{AssetConfigNotFound, InvalidPath};
use crate::error::load_config::AssetLoadConfigError;
use crate::error::load_config::AssetLoadConfigError::{LoadRuleFailed, MalformedAssetConfigFile};
use crate::error::AssetLoadConfigError;
use crate::error::AssetLoadConfigError::{LoadRuleFailed, MalformedAssetConfigFile};
use crate::error::GetAssetConfigError;
use crate::error::GetAssetConfigError::{AssetConfigNotFound, InvalidPath};

use derivative::Derivative;
use globset::GlobMatcher;
Expand Down Expand Up @@ -269,7 +269,7 @@ impl AssetConfig {
/// and pretty-printing of the `AssetConfigRule` data structure.
mod rule_utils {
use super::{AssetConfig, AssetConfigRule, CacheConfig, HeadersConfig, Maybe};
use crate::error::load_rule::LoadRuleError;
use crate::error::LoadRuleError;
use globset::{Glob, GlobMatcher};
use serde::{Deserialize, Serializer};
use serde_json::Value;
Expand Down
8 changes: 4 additions & 4 deletions src/canisters/frontend/ic-asset/src/batch_upload/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use crate::asset::content_encoder::ContentEncoder;
use crate::batch_upload::semaphores::Semaphores;
use crate::canister_api::methods::chunk::create_chunk;
use crate::canister_api::types::asset::AssetDetails;
use crate::error::create_chunk::CreateChunkError;
use crate::error::create_encoding::CreateEncodingError;
use crate::error::create_encoding::CreateEncodingError::EncodeContentFailed;
use crate::error::create_project_asset::CreateProjectAssetError;
use crate::error::CreateChunkError;
use crate::error::CreateEncodingError;
use crate::error::CreateEncodingError::EncodeContentFailed;
use crate::error::CreateProjectAssetError;

use candid::Nat;
use futures::future::try_join_all;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use std::collections::HashMap;

use ic_agent::AgentError;
use ic_agent::{
agent::{RejectCode, RejectResponse},
AgentError,
};
use ic_utils::call::SyncCall;
use ic_utils::Canister;

use crate::canister_api::{
methods::method_names::GET_ASSET_PROPERTIES,
types::asset::{AssetDetails, AssetProperties, GetAssetPropertiesArgument},
};
use crate::error::get_asset_properties::GetAssetPropertiesError;
use crate::error::get_asset_properties::GetAssetPropertiesError::GetAssetPropertiesFailed;
use crate::error::GetAssetPropertiesError;
use crate::error::GetAssetPropertiesError::GetAssetPropertiesFailed;

pub(crate) async fn get_assets_properties(
canister: &Canister<'_>,
Expand All @@ -23,10 +26,11 @@ pub(crate) async fn get_assets_properties(
}
// older canisters don't have get_assets_properties method
// therefore we can break the loop
Err(AgentError::ReplicaError {
Err(AgentError::ReplicaError(RejectResponse {
reject_code,
reject_message,
}) if reject_code == 3
..
})) if reject_code == RejectCode::DestinationInvalid
&& (reject_message
.contains(&format!("has no query method '{GET_ASSET_PROPERTIES}'"))
|| reject_message.contains("query method does not exist")) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::batch_upload::retryable::retryable;
use crate::batch_upload::semaphores::Semaphores;
use crate::canister_api::methods::method_names::CREATE_CHUNK;
use crate::canister_api::types::batch_upload::common::{CreateChunkRequest, CreateChunkResponse};
use crate::error::create_chunk::CreateChunkError;
use crate::error::CreateChunkError;

use backoff::backoff::Backoff;
use backoff::ExponentialBackoffBuilder;
Expand Down Expand Up @@ -51,15 +51,15 @@ pub(crate) async fn create_chunk(
Ok(response) => {
// failure to decode the response is not retryable
let response = Decode!(&response, CreateChunkResponse)
.map_err(CreateChunkError::DecodeCreateChunkResponseFailed)?;
.map_err(CreateChunkError::DecodeCreateChunkResponse)?;
return Ok(response.chunk_id);
}
Err(agent_err) if !retryable(&agent_err) => {
return Err(CreateChunkError::Agent(agent_err));
return Err(CreateChunkError::CreateChunk(agent_err));
}
Err(agent_err) => match retry_policy.next_backoff() {
Some(duration) => tokio::time::sleep(duration).await,
None => return Err(CreateChunkError::Agent(agent_err)),
None => return Err(CreateChunkError::CreateChunk(agent_err)),
},
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::common::*;
use crate::error::downgrade_commit_batch_arguments::DowngradeCommitBatchArgumentsV1ToV0Error;
use crate::error::downgrade_commit_batch_arguments::DowngradeCommitBatchArgumentsV1ToV0Error::V0SetAssetPropertiesNotSupported;
use crate::error::DowngradeCommitBatchArgumentsV1ToV0Error;
use crate::error::DowngradeCommitBatchArgumentsV1ToV0Error::V0SetAssetPropertiesNotSupported;

use candid::{CandidType, Nat};

Expand Down
2 changes: 2 additions & 0 deletions src/canisters/frontend/ic-asset/src/error/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use crate::error::downgrade_commit_batch_arguments::DowngradeCommitBatchArgument

use thiserror::Error;

/// Errors that occur when trying to deploy to an older version of the asset canister.
#[derive(Error, Debug)]
pub enum CompatibilityError {
/// Failed to downgrade from v1::CommitBatchArguments to v0::CommitBatchArguments.
#[error("Failed to downgrade from v1::CommitBatchArguments to v0::CommitBatchArguments: {0}. Please upgrade your asset canister, or use older tooling (dfx<=v-0.13.1 or icx-asset<=0.20.0)")]
DowngradeV1TOV0Failed(DowngradeCommitBatchArgumentsV1ToV0Error),
}
6 changes: 6 additions & 0 deletions src/canisters/frontend/ic-asset/src/error/compute_evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ use crate::error::hash_content::HashContentError;
use ic_agent::AgentError;
use thiserror::Error;

/// Errors related to computing evidence for a proposed update.
#[derive(Error, Debug)]
pub enum ComputeEvidenceError {
/// Failed when inspecting assets to be updated.
#[error(transparent)]
ProcessProjectAsset(#[from] CreateProjectAssetError),

/// Failed when determining which assets and encodings changed.
#[error(transparent)]
GatherAssetDescriptors(#[from] GatherAssetDescriptorsError),

/// Failed when reading assets properties from the asset canister.
#[error(transparent)]
GetAssetProperties(#[from] GetAssetPropertiesError),

/// Failed when computing hashes of asset content.
#[error(transparent)]
HashContent(#[from] HashContentError),

/// Failed to list assets in the asset canister.
#[error("Failed to list assets: {0}")]
ListAssets(AgentError),
}
9 changes: 6 additions & 3 deletions src/canisters/frontend/ic-asset/src/error/create_chunk.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use ic_agent::AgentError;
use thiserror::Error;

/// Errors related to creating a chunk.
#[derive(Error, Debug)]
pub enum CreateChunkError {
#[error(transparent)]
Agent(#[from] AgentError),
/// Failed in call to create_chunk, or in waiting for response.
#[error("Failed to create chunk: {0}")]
CreateChunk(AgentError),

/// Failed to decode the create chunk response.
#[error("Failed to decode create chunk response: {0}")]
DecodeCreateChunkResponseFailed(candid::Error),
DecodeCreateChunkResponse(candid::Error),
}
3 changes: 3 additions & 0 deletions src/canisters/frontend/ic-asset/src/error/create_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use crate::error::create_chunk::CreateChunkError;

use thiserror::Error;

/// Errors related to creating/uploading an asset content encoding to the asset canister
#[derive(Error, Debug)]
pub enum CreateEncodingError {
/// Failed when creating a chunk.
#[error("Failed to create chunk: {0}")]
CreateChunkFailed(CreateChunkError),

/// Failed when encoding asset content.
#[error("Failed to encode content of '{0}' with {1} encoding: {2}")]
EncodeContentFailed(String, ContentEncoder, std::io::Error),
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ use dfx_core::error::fs::FsError;

use thiserror::Error;

/// Errors related to creating an asset found in the project in the asset canister.
#[derive(Error, Debug)]
pub enum CreateProjectAssetError {
/// Failed to create an asset encoding in the asset canister.
#[error("Failed to create encoding: {0}")]
CreateEncodingError(#[from] CreateEncodingError),

/// Failed to find out the file size of an asset.
#[error("Failed to determine asset size: {0}")]
DetermineAssetSizeFailed(FsError),

/// Failed to load asset content from the filesystem.
#[error("Failed to load asset content: {0}")]
LoadContentFailed(FsError),
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use thiserror::Error;

/// Errors related to downgrading CommitBatchArguments for use with a v0 asset canister.
#[derive(Error, Debug)]
pub enum DowngradeCommitBatchArgumentsV1ToV0Error {
/// Asset canister v0 does not support SetAssetProperties.
#[error("SetAssetProperties is not supported")]
V0SetAssetPropertiesNotSupported,
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@ use dfx_core::error::fs::FsError;
use std::path::PathBuf;
use thiserror::Error;

/// Errors related to building asset list and reading asset configurations.
#[derive(Error, Debug)]
pub enum GatherAssetDescriptorsError {
/// An asset with a given key exists in more than one source directory.
#[error("Asset with key '{0}' defined at {1} and {2}")]
DuplicateAssetKey(String, Box<PathBuf>, Box<PathBuf>),

/// Failed to get asset configuration.
#[error("Failed to get asset configuration: {0}")]
GetAssetConfigFailed(#[from] GetAssetConfigError),

/// Failed to canonicalize a directory entry.
#[error("Invalid directory entry: {0}")]
InvalidDirectoryEntry(FsError),

/// Failed to canonicalize a source directory.
#[error("Invalid source directory: {0}")]
InvalidSourceDirectory(FsError),

/// Failed to load the asset configuration for a directory.
#[error("Failed to load asset configuration: {0}")]
LoadConfigFailed(AssetLoadConfigError),
}
3 changes: 3 additions & 0 deletions src/canisters/frontend/ic-asset/src/error/get_asset_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ use dfx_core::error::fs::FsError;
use std::path::PathBuf;
use thiserror::Error;

/// Errors related to getting asset configuration.
#[derive(Error, Debug)]
pub enum GetAssetConfigError {
/// An asset exists, but it does not have a configuration.
#[error("No configuration found for asset '{0}'")]
AssetConfigNotFound(PathBuf),

/// The path to an asset was invalid.
#[error("Invalid asset path: {0}")]
InvalidPath(FsError),
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use ic_agent::AgentError;
use thiserror::Error;

/// Errors related to getting asset properties.
#[derive(Error, Debug)]
pub enum GetAssetPropertiesError {
/// The call to get_asset_properties failed.
#[error("Failed to get asset properties for {0}: {1}")]
GetAssetPropertiesFailed(String, AgentError),
}
3 changes: 3 additions & 0 deletions src/canisters/frontend/ic-asset/src/error/hash_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use crate::asset::content_encoder::ContentEncoder;
use dfx_core::error::fs::FsError;
use thiserror::Error;

/// Errors related to hashing asset content.
#[derive(Error, Debug)]
pub enum HashContentError {
/// Failed to encode the content in order to compute the hash.
#[error("Failed to encode content of '{0}' with {1} encoding: {2}")]
EncodeContentFailed(String, ContentEncoder, std::io::Error),

/// Failed to load asset content from the filesystem.
#[error("Failed to load content: {0}")]
LoadContentFailed(FsError),
}
6 changes: 6 additions & 0 deletions src/canisters/frontend/ic-asset/src/error/load_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ use dfx_core::error::fs::FsError;
use std::path::PathBuf;
use thiserror::Error;

/// Errors related to loading asset configuration.
#[derive(Error, Debug)]
pub enum AssetLoadConfigError {
/// Failed a filesystem operation; the inner error contains the details.
#[error(transparent)]
FsError(#[from] FsError),

/// Failed to canonicalize the root directory.
#[error("root_dir '{0}' is expected to be a canonical path")]
InvalidRootDir(PathBuf),

/// Failed to load a rule from the asset configuration file.
#[error("Failed to load rule in {0}: {1}")]
LoadRuleFailed(PathBuf, LoadRuleError),

/// An asset configuration file was not valid JSON5.
#[error("Malformed JSON asset config file '{0}': {1}")]
MalformedAssetConfigFile(PathBuf, json5::Error),

/// both `assets.json` and `assets.json5` files exist in the same directory.
#[error("both {} and {} files exist in the same directory (dir = {:?})",
crate::asset::config::ASSETS_CONFIG_FILENAME_JSON,
crate::asset::config::ASSETS_CONFIG_FILENAME_JSON5,
Expand Down
3 changes: 3 additions & 0 deletions src/canisters/frontend/ic-asset/src/error/load_rule.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::path::PathBuf;
use thiserror::Error;

/// Errors related to loading an asset configuration rule.
#[derive(Error, Debug)]
pub enum LoadRuleError {
/// The match string could not be combined with the root directory to form a valid string.
#[error("Failed to combine {0} and {1} into a string (to be later used as a glob pattern)")]
FormGlobPatternFailed(PathBuf, String),

/// The glob pattern was not valid.
#[error("{0} is not a valid glob pattern: {1}")]
InvalidGlobPattern(String, globset::Error),
}
Loading

0 comments on commit 5ba396f

Please sign in to comment.