Skip to content

Commit

Permalink
feat(asset-canister): Improve prepare_commit error messages (#3930)
Browse files Browse the repository at this point in the history
Improve `prepare_commit_batch` error message

---------

Co-authored-by: Severin Siffert <[email protected]>
  • Loading branch information
Sawchord and sesi200 authored Oct 1, 2024
1 parent 9ef469f commit 3050c03
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(())
Expand Down
19 changes: 12 additions & 7 deletions src/canisters/frontend/ic-certified-assets/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
Expand All @@ -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),
}
}
Expand Down Expand Up @@ -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),
}
}
Expand Down
Binary file modified src/distributed/assetstorage.wasm.gz
Binary file not shown.

0 comments on commit 3050c03

Please sign in to comment.