Skip to content
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: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

# UNRELEASED

## Dependencies

## Fixes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't match the changelog format we've used so far

### fix: correct `dfx sns` example commands in documentation

Fixed incorrect commands `dfx sns config create` and `dfx sns config validate` in the `dfx sns` CLI reference examples. The correct commands are `dfx sns create` and `dfx sns validate`.

### fix: Failure to query an asset canister's API version no longer gets misinterpreted as the canister being outdated

### Motoko

Updated Motoko to [1.2.0](https://github.com/dfinity/motoko/releases/tag/1.2.0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
use crate::canister_api::methods::method_names::API_VERSION;
use ic_agent::AgentError;
use ic_utils::Canister;
use ic_utils::call::SyncCall;

pub(crate) async fn api_version(canister: &Canister<'_>) -> u16 {
canister
.query(API_VERSION)
.build()
.call()
.await
.map_or(0, |v: (u16,)| v.0)
const CANISTER_METHOD_NOT_FOUND: &str = "IC0536";

fn is_method_not_found(err: &AgentError) -> bool {
match err {
AgentError::CertifiedReject { reject, .. }
| AgentError::UncertifiedReject { reject, .. } => {
reject.error_code.as_deref() == Some(CANISTER_METHOD_NOT_FOUND)
}
_ => false,
}
}

pub(crate) async fn api_version(canister: &Canister<'_>) -> Result<u16, AgentError> {
match canister.query(API_VERSION).build().call().await {
Ok((version,)) => Ok(version),
// If the canister doesn't have the `api_version` method, it's an old version of the API.
Err(e) if is_method_not_found(&e) => Ok(0),
Err(e) => Err(e),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use thiserror::Error;
/// Errors related to preparing synchronization operations for a proposal.
#[derive(Error, Debug)]
pub enum PrepareSyncForProposalError {
/// Failed when querying the asset canister for its API version.
#[error("Failed to query asset canister API version")]
ApiVersionQueryFailed(#[source] AgentError),

/// Failed while requesting that the asset canister compute evidence.
#[error("Failed to compute evidence")]
ComputeEvidence(#[source] AgentError),
Expand Down
4 changes: 4 additions & 0 deletions src/canisters/frontend/ic-asset/src/error/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use thiserror::Error;
/// Errors related to the sync process.
#[derive(Error, Debug)]
pub enum SyncError {
/// Failed when querying the asset canister for its API version.
#[error("Failed to query asset canister API version")]
ApiVersionQueryFailed(#[source] AgentError),

/// Failed when calling commit_batch
#[error("Failed to commit batch")]
CommitBatchFailed(#[source] AgentError),
Expand Down
4 changes: 4 additions & 0 deletions src/canisters/frontend/ic-asset/src/error/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use thiserror::Error;
/// Errors encountered during the upload process.
#[derive(Error, Debug)]
pub enum UploadError {
/// Failed when querying the asset canister for its API version.
#[error("Failed to query asset canister API version")]
ApiVersionQueryFailed(#[source] AgentError),

/// Failed when calling commit_batch.
#[error("Commit batch failed")]
CommitBatchFailed(#[source] AgentError),
Expand Down
8 changes: 5 additions & 3 deletions src/canisters/frontend/ic-asset/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::error::GatherAssetDescriptorsError::{
};
use crate::error::PrepareSyncForProposalError;
use crate::error::SyncError;
use crate::error::SyncError::CommitBatchFailed;
use crate::error::SyncError::{ApiVersionQueryFailed, CommitBatchFailed};
use crate::error::UploadContentError;
use crate::error::UploadContentError::{CreateBatchFailed, ListAssetsFailed};
use crate::progress::{AssetSyncProgressRenderer, AssetSyncState};
Expand Down Expand Up @@ -155,7 +155,7 @@ pub async fn sync(
logger: &Logger,
progress: Option<&dyn AssetSyncProgressRenderer>,
) -> Result<(), SyncError> {
let canister_api_version = api_version(canister).await;
let canister_api_version = api_version(canister).await.map_err(ApiVersionQueryFailed)?;
let commit_batch_args = upload_content_and_assemble_sync_operations(
canister,
canister_api_version,
Expand Down Expand Up @@ -296,7 +296,9 @@ pub async fn prepare_sync_for_proposal(
logger: &Logger,
progress: Option<&dyn AssetSyncProgressRenderer>,
) -> Result<(Nat, ByteBuf), PrepareSyncForProposalError> {
let canister_api_version = api_version(canister).await;
let canister_api_version = api_version(canister)
.await
.map_err(PrepareSyncForProposalError::ApiVersionQueryFailed)?;
let arg = upload_content_and_assemble_sync_operations(
canister,
canister_api_version,
Expand Down
8 changes: 5 additions & 3 deletions src/canisters/frontend/ic-asset/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use crate::canister_api::methods::{
};
use crate::canister_api::types::batch_upload::v0;
use crate::error::CompatibilityError::DowngradeV1TOV0Failed;
use crate::error::UploadError::{self, CommitBatchFailed, CreateBatchFailed, ListAssetsFailed};
use crate::error::UploadError::{
self, ApiVersionQueryFailed, CommitBatchFailed, CreateBatchFailed, ListAssetsFailed,
};
use ic_utils::Canister;
use slog::{Logger, info};
use std::collections::HashMap;
Expand All @@ -41,7 +43,7 @@ pub async fn upload(
info!(logger, "Starting batch.");

let batch_id = create_batch(canister).await.map_err(CreateBatchFailed)?;
let canister_api_version = api_version(canister).await;
let canister_api_version = api_version(canister).await.map_err(ApiVersionQueryFailed)?;

info!(logger, "Staging contents of new and changed assets:");

Expand Down Expand Up @@ -69,7 +71,7 @@ pub async fn upload(
.await
.map_err(UploadError::AssembleCommitBatchArgumentFailed)?;

let canister_api_version = api_version(canister).await;
let canister_api_version = api_version(canister).await.map_err(ApiVersionQueryFailed)?;
info!(logger, "Committing batch.");
match canister_api_version {
0 => {
Expand Down
Loading