Skip to content

Commit

Permalink
Add error to FailedProposalExecution response (#749)
Browse files Browse the repository at this point in the history
* Add error to FailedProposalExecution response

Minimal information is shown when a proposal execution fails, and this could give users a better clue of what went wrong.
It should probably be used in all reply_on_error handles.

* Avoid possible panic from unwrap_err()
  • Loading branch information
ismellike authored Sep 15, 2023
1 parent 3518a28 commit 7776858
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion contracts/proposal/dao-proposal-condorcet/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,10 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
let mut proposal = PROPOSAL.load(deps.storage, proposal_id as u32)?;
proposal.set_execution_failed();
PROPOSAL.save(deps.storage, proposal_id as u32, &proposal)?;

Ok(Response::default()
.add_attribute("proposal_execution_failed", proposal_id.to_string()))
.add_attribute("proposal_execution_failed", proposal_id.to_string())
.add_attribute("error", msg.result.into_result().err().unwrap_or_default()))
}
_ => unimplemented!("pre-propose and hooks not yet supported"),
}
Expand Down
5 changes: 4 additions & 1 deletion contracts/proposal/dao-proposal-multiple/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,10 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
}
None => Err(ContractError::NoSuchProposal { id: proposal_id }),
})?;
Ok(Response::new().add_attribute("proposal execution failed", proposal_id.to_string()))

Ok(Response::new()
.add_attribute("proposal execution failed", proposal_id.to_string())
.add_attribute("error", msg.result.into_result().err().unwrap_or_default()))
}
TaggedReplyId::FailedProposalHook(idx) => {
let addr = PROPOSAL_HOOKS.remove_hook_by_index(deps.storage, idx)?;
Expand Down
4 changes: 3 additions & 1 deletion contracts/proposal/dao-proposal-single/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,9 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
None => Err(ContractError::NoSuchProposal { id: proposal_id }),
})?;

Ok(Response::new().add_attribute("proposal_execution_failed", proposal_id.to_string()))
Ok(Response::new()
.add_attribute("proposal_execution_failed", proposal_id.to_string())
.add_attribute("error", msg.result.into_result().err().unwrap_or_default()))
}
TaggedReplyId::FailedProposalHook(idx) => {
let addr = PROPOSAL_HOOKS.remove_hook_by_index(deps.storage, idx)?;
Expand Down

0 comments on commit 7776858

Please sign in to comment.