diff --git a/CHANGELOG.md b/CHANGELOG.md index d867c59272..1c0f482730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,14 @@ ## Dependencies +### Frontend canister + +#### feat: Better error messages when proposing a batch + +Add the batch id in the error messages of `propose_commit_batch`. + +Module hash: 2c9e30df9be951a6884c702a97bbb8c0b438f33d4208fa612b1de6fb1752db76 + ### Motoko Updated Motoko to [0.13.0](https://github.com/dfinity/motoko/releases/tag/0.13.0) diff --git a/src/canisters/frontend/ic-certified-assets/src/state_machine.rs b/src/canisters/frontend/ic-certified-assets/src/state_machine.rs index 7b859fbcad..fa4b04bad6 100644 --- a/src/canisters/frontend/ic-certified-assets/src/state_machine.rs +++ b/src/canisters/frontend/ic-certified-assets/src/state_machine.rs @@ -625,7 +625,7 @@ impl State { .get_mut(&batch_id) .ok_or_else(|| "batch not found".to_string())?; if batch.commit_batch_arguments.is_some() { - return Err("batch has been proposed".to_string()); + return Err(format!("batch {} has been proposed", batch_id)); } batch.expires_at = Int::from(now + BATCH_EXPIRY_NANOS); @@ -674,7 +674,10 @@ impl State { .get_mut(&arg.batch_id) .expect("batch not found"); if batch.commit_batch_arguments.is_some() { - return Err("batch already has proposed CommitBatchArguments".to_string()); + return Err(format!( + "batch {} already has proposed CommitBatchArguments", + arg.batch_id + )); }; batch.commit_batch_arguments = Some(arg); Ok(()) diff --git a/src/canisters/frontend/ic-certified-assets/src/tests.rs b/src/canisters/frontend/ic-certified-assets/src/tests.rs index a1669c2942..1bc56d1b0c 100644 --- a/src/canisters/frontend/ic-certified-assets/src/tests.rs +++ b/src/canisters/frontend/ic-certified-assets/src/tests.rs @@ -699,12 +699,17 @@ fn can_propose_commit_batch_exactly_once() { let batch_1 = state.create_batch(time_now).unwrap(); let args = CommitBatchArguments { - batch_id: batch_1, + batch_id: batch_1.clone(), operations: vec![], }; assert_eq!(Ok(()), state.propose_commit_batch(args.clone())); match state.propose_commit_batch(args) { - Err(err) if err == *"batch already has proposed CommitBatchArguments" => {} + Err(err) + if err + == format!( + "batch {} already has proposed CommitBatchArguments", + batch_1, + ) => {} other => panic!("expected batch already proposed error, got: {:?}", other), }; } @@ -730,17 +735,17 @@ fn cannot_create_chunk_in_proposed_batch_() { }, time_now, ) { - Err(err) if err == *"batch has been proposed" => {} + Err(err) if err == format!("batch {} has been proposed", batch_1) => {} other => panic!("expected batch already proposed error, got: {:?}", other), } match state.create_chunks( CreateChunksArg { - batch_id: batch_1, + batch_id: batch_1.clone(), content: vec![ByteBuf::from(BODY.to_vec())], }, time_now, ) { - Err(err) if err == *"batch has been proposed" => {} + Err(err) if err == format!("batch {} has been proposed", batch_1) => {} other => panic!("expected batch already proposed error, got: {:?}", other), } } @@ -822,12 +827,12 @@ fn batches_with_evidence_do_not_expire() { match state.create_chunk( CreateChunkArg { - batch_id: batch_1, + batch_id: batch_1.clone(), content: ByteBuf::from(BODY.to_vec()), }, time_now, ) { - Err(err) if err == *"batch has been proposed" => {} + Err(err) if err == format!("batch {} has been proposed", batch_1) => {} other => panic!("expected batch already proposed error, got: {:?}", other), } } diff --git a/src/distributed/assetstorage.wasm.gz b/src/distributed/assetstorage.wasm.gz index 9afc172fe4..1b691cb7ca 100755 Binary files a/src/distributed/assetstorage.wasm.gz and b/src/distributed/assetstorage.wasm.gz differ