You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error Fail();
error ParamFailString(string);
contractTasksSystemisSystem {
function errorRevert() public {
revertFail();
}
function stringParamRevert() public {
revertParamFailString("Parameter fail");
}
I tried to use a uint256 parameter and it had the same results. Putting errors in a library didn't have any effect.
For an easy replication, use the react template and replace App.tsx with:
import{getTxpoolContent}from"viem/actions";import{useMUD}from"./MUDContext";import{useState}from"react"conststyleUnset={all: "unset"}asconst;constErrButton=attrs=>{return(<><buttononClick={asyncevent=>{try{awaitattrs.fun([]);}catch(err){attrs.set(JSON.stringify(err,undefined,2))}}}>{attrs.msg}</button></>)}exportconstApp=()=>{const{network: { worldContract, tables, useStore },systemCalls: { addTask, toggleTask, deleteTask },}=useMUD();const[result,setResult]=useState();consttasks=useStore((state)=>{constrecords=Object.values(state.getRecords(tables.Tasks));records.sort((a,b)=>Number(a.value.createdAt-b.value.createdAt));returnrecords;});return(<><table><tbody>{tasks.map((task)=>(<trkey={task.id}><tdalign="right"><inputtype="checkbox"checked={task.value.completedAt>0n}title={task.value.completedAt===0n ? "Mark task as completed" : "Mark task as incomplete"}onChange={async(event)=>{event.preventDefault();constcheckbox=event.currentTarget;checkbox.disabled=true;try{awaittoggleTask(task.key.id);}finally{checkbox.disabled=false;}}}/></td><td>{task.value.completedAt>0n ? <s>{task.value.description}</s>:<>{task.value.description}</>}</td><tdalign="right"><buttontype="button"title="Delete task"style={styleUnset}onClick={async(event)=>{event.preventDefault();if(!window.confirm("Are you sure you want to delete this task?"))return;constbutton=event.currentTarget;button.disabled=true;try{awaitdeleteTask(task.key.id);}finally{button.disabled=false;}}}>×</button></td></tr>))}</tbody><tfoot><tr><td><inputtype="checkbox"disabled/></td><tdcolSpan={2}><formonSubmit={async(event)=>{event.preventDefault();constform=event.currentTarget;constfieldset=form.querySelector("fieldset");if(!(fieldsetinstanceofHTMLFieldSetElement))return;constformData=newFormData(form);constdesc=formData.get("description");if(typeofdesc!=="string")return;fieldset.disabled=true;try{awaitaddTask(desc);form.reset();}finally{
fieldset.disabled=false;}}}><fieldsetstyle={styleUnset}><inputtype="text"name="description"/>{" "}
<buttontype="submit"title="Add task">Add</button></fieldset></form></td></tr></tfoot></table><ErrButtonfun={worldContract.write.app__stringRevert}msg="String revert (old style)"set={setResult}/><br/><ErrButtonfun={worldContract.write.app__errorRevert}msg="Revert with error Fail()"set={setResult}/><ErrButtonfun={worldContract.write.app__errorRevertLib}msg="Revert with error Errors.Fail()"set={setResult}/><br/><ErrButtonfun={worldContract.write.app__stringParamRevert}msg='Revert with error ParamFailString("Parameter fail")'set={setResult}/><ErrButtonfun={worldContract.write.app__stringParamRevertLib}msg='Revert with error Errors.ParamFailString("Parameter fail")'set={setResult}/><br/><ErrButtonfun={worldContract.write.app__uintParamRevert}msg='Revert with error ParamFailUint(0x0BAD60A7)'set={setResult}/><ErrButtonfun={worldContract.write.app__uintParamRevertLib}msg='Revert with error Errors.ParamFailUint(0x0BAD60A7)'set={setResult}/><br/><h4>Message</h4><pre>{result}</pre></>);};
And TasksSystem.sol with:
// SPDX-License-Identifier: MITpragma solidity>=0.8.24;
import { System } from"@latticexyz/world/src/System.sol";
import { Tasks, TasksData } from"../codegen/index.sol";
error Fail();
error ParamFailString(string);
error ParamFailUint(uint256);
libraryErrors {
error Fail();
error ParamFailString(string);
error ParamFailUint(uint256);
}
contractTasksSystemisSystem {
function addTask(stringmemorydescription) publicreturns (bytes32id) {
id =keccak256(abi.encode(block.prevrandao, _msgSender(), description));
Tasks.set(id, TasksData({ description: description, createdAt: block.timestamp, completedAt: 0 }));
}
function completeTask(bytes32id) public {
Tasks.setCompletedAt(id, block.timestamp);
}
function resetTask(bytes32id) public {
Tasks.setCompletedAt(id, 0);
}
function deleteTask(bytes32id) public {
Tasks.deleteRecord(id);
}
function stringRevert() public {
revert("Old style revert, with a string");
}
function errorRevert() public {
revertFail();
}
function stringParamRevert() public {
revertParamFailString("Parameter fail");
}
function uintParamRevert() public {
revertParamFailUint(0x0BAD60A7);
}
function errorRevertLib() public {
revert Errors.Fail();
}
function stringParamRevertLib() public {
revert Errors.ParamFailString("Parameter fail");
}
function uintParamRevertLib() public {
revert Errors.ParamFailUint(0x0BAD60A7);
}
}
The text was updated successfully, but these errors were encountered:
I have this Solidity code:
When I call
app__errorRevert
, I catch this error:When I call
app__stringParamRevert
, thedetails
don't have any additional information, just that the execution failed:I tried to use a
uint256
parameter and it had the same results. Putting errors in a library didn't have any effect.For an easy replication, use the
react
template and replaceApp.tsx
with:And
TasksSystem.sol
with:The text was updated successfully, but these errors were encountered: