Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: error handling #149

Merged
merged 42 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
dc216d7
Added WorkspaceError{,Kind}
ChaoticTempest Jun 4, 2022
57ec680
Added workspace error kind for sandbox
ChaoticTempest Jun 4, 2022
8496fa8
Replaced types errors w/ WorkspaceError
ChaoticTempest Jun 4, 2022
3cb52cd
Moved from ErrorKind to thiserror
ChaoticTempest Jun 7, 2022
44cb249
Added SerializationError type
ChaoticTempest Jun 8, 2022
b3ba295
Added ExecutionError
ChaoticTempest Jun 8, 2022
86aa7dc
Added errors to network related items
ChaoticTempest Jun 8, 2022
aedddfa
Added error handling to view
ChaoticTempest Jun 8, 2022
41c5a34
Moved all client anyhow Error to workspace Error
ChaoticTempest Jun 8, 2022
73691c4
Rearrange Error to be at top level
ChaoticTempest Jun 9, 2022
da9bb37
More serialization error for result.rs
ChaoticTempest Jun 9, 2022
09937a6
Last bits of result.rs errors
ChaoticTempest Jun 9, 2022
a231ae2
Added sandbox specific error handling
ChaoticTempest Jun 9, 2022
f7df5d8
Sandbox patch
ChaoticTempest Jun 9, 2022
4b806de
Final bit of anyhow::Result removed
ChaoticTempest Jun 9, 2022
e68dc74
Specific RpcError
ChaoticTempest Jun 9, 2022
8167411
Cleanup
ChaoticTempest Jun 13, 2022
e440111
Added ParseError specific kind
ChaoticTempest Jun 13, 2022
c5b2783
Surface WorkspacError
ChaoticTempest Jun 13, 2022
ae45579
Small cleanup
ChaoticTempest Jun 13, 2022
1cd6e21
Added some docs
ChaoticTempest Jun 13, 2022
24c70fb
Added more docs
ChaoticTempest Jun 14, 2022
1eddc74
Moved errors to error module & added RpcError into client.rs
ChaoticTempest Jun 14, 2022
115c338
Changed internal repr of RpcError
ChaoticTempest Jun 14, 2022
4792d84
Some more cleanup
ChaoticTempest Jun 14, 2022
9201a5d
Cleanup Result path
ChaoticTempest Jun 14, 2022
ce5875e
Fmt
ChaoticTempest Jun 14, 2022
2b7effa
Clippy
ChaoticTempest Jun 14, 2022
b9e2d66
Fmt again
ChaoticTempest Jun 15, 2022
dd5e72f
Addressed most comments
ChaoticTempest Jun 17, 2022
b5aec3b
Fixed Sync/Send | remove AccountError | made ParseError(String)
ChaoticTempest Jun 29, 2022
a887470
Merge branch 'main' of https://github.com/near/runner-rs into feat/er…
ChaoticTempest Jul 26, 2022
2309227
Fix io error from_file
ChaoticTempest Jul 26, 2022
0f9d10e
Moved Error to mostly opaque type
ChaoticTempest Jul 28, 2022
40e042d
Added downcasting and docs
ChaoticTempest Jul 28, 2022
838d760
Added deferred error handling on args_{json, borsh}
ChaoticTempest Jul 28, 2022
275836d
Fix test
ChaoticTempest Jul 29, 2022
dec749d
Export Result to workspaces root
ChaoticTempest Aug 5, 2022
1fc71d9
Remove exposed from impls
ChaoticTempest Aug 5, 2022
192a8db
Addressed comments
ChaoticTempest Aug 8, 2022
dead5b8
Make less redundant usage of deferred error
ChaoticTempest Aug 8, 2022
2c08ead
Added error message w/ timeout env var
ChaoticTempest Aug 8, 2022
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Then we'll go directly into making a call into the contract, and initialize the
.call(&worker, "new_default_meta")
.args_json(json!({
"owner_id": contract.id(),
}))?
}))
.transact()
.await?;

Expand All @@ -100,7 +100,7 @@ Afterwards, let's mint an NFT via `nft_mint`. This showcases some extra argument
"dscription": "Tallest mountain in charted solar system",
"copies": 1,
},
}))?
}))
.deposit(deposit)
// nft_mint might consume more than default gas, so supply our own gas value:
.gas(near_units::parse_gas("300 T"))
Expand Down Expand Up @@ -160,7 +160,7 @@ async fn call_my_func(worker: Worker<impl Network>, contract: &Contract) -> anyh
contract.call(&worker, "contract_function")
.args_json(serde_json::json!({
"message": msg,
})?
})
.transact()
.await?;
Ok(())
Expand Down Expand Up @@ -220,7 +220,7 @@ Following that we will have to init the contract again with our own metadata. Th
.args_json(serde_json::json!({
"arg1": value1,
"arg2": value2,
}))?
}))
.transact()
.await?;

Expand Down
12 changes: 6 additions & 6 deletions examples/src/croncat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async fn main() -> anyhow::Result<()> {
"function_id": "increment",
"cadence": "*/1 * * * * *",
"recurring": true,
}))?
}))
.max_gas()
.deposit(parse_near!("1 N"))
.transact()
Expand Down Expand Up @@ -101,7 +101,7 @@ pub async fn run_scheduled_tasks(
// Register the agent to eventually execute the task
let outcome = agent
.call(&worker, contract.id(), "register_agent")
.args_json(json!({}))?
.args_json(json!({}))
.deposit(parse_near!("0.00226 N"))
.transact()
.await?;
Expand All @@ -110,7 +110,7 @@ pub async fn run_scheduled_tasks(
// Check the right agent was registered correctly:
let registered_agent = contract
.call(&worker, "get_agent")
.args_json(json!({ "account_id": agent.id() }))?
.args_json(json!({ "account_id": agent.id() }))
.view()
.await?
.json::<Option<Agent>>()?
Expand Down Expand Up @@ -148,7 +148,7 @@ pub async fn run_scheduled_tasks(
// the manager contract, and we want to eventually withdraw this amount.
let agent_details = contract
.call(&worker, "get_agent")
.args_json(json!({"account_id": agent.id()}))?
.args_json(json!({"account_id": agent.id()}))
.view()
.await?
.json::<Option<Agent>>()?
Expand All @@ -167,7 +167,7 @@ pub async fn run_scheduled_tasks(
// contract:
let agent_details = contract
.call(&worker, "get_agent")
.args_json(json!({"account_id": agent.id() }))?
.args_json(json!({"account_id": agent.id() }))
.view()
.await?
.json::<Option<Agent>>()?
Expand All @@ -191,7 +191,7 @@ pub async fn run_scheduled_tasks(
// Check to see if the agent has been successfully unregistered
let removed_agent: Option<Agent> = contract
.call(&worker, "get_agent")
.args_json(json!({"account_id": agent.id() }))?
.args_json(json!({"account_id": agent.id() }))
.view()
.await?
.json()?;
Expand Down
4 changes: 2 additions & 2 deletions examples/src/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn main() -> anyhow::Result<()> {
.call(&worker, "new_default_meta")
.args_json(json!({
"owner_id": contract.id(),
}))?
}))
.transact()
.await?;

Expand All @@ -31,7 +31,7 @@ async fn main() -> anyhow::Result<()> {
"dscription": "Tallest mountain in charted solar system",
"copies": 1,
},
}))?
}))
.deposit(deposit)
.transact()
.await?;
Expand Down
24 changes: 12 additions & 12 deletions examples/src/ref_finance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ async fn create_ref(owner: &Account, worker: &Worker<Sandbox>) -> anyhow::Result
"owner_id": ref_finance.id(),
"exchange_fee": 4,
"referral_fee": 1,
}))?
}))
.transact()
.await?;

owner
.call(&worker, ref_finance.id(), "storage_deposit")
.args_json(serde_json::json!({}))?
.args_json(serde_json::json!({}))
.deposit(parse_near!("30 mN"))
.transact()
.await?;
Expand All @@ -69,13 +69,13 @@ async fn create_wnear(owner: &Account, worker: &Worker<Sandbox>) -> anyhow::Resu
.args_json(serde_json::json!({
"owner_id": owner.id(),
"total_supply": parse_near!("1,000,000,000 N"),
}))?
}))
.transact()
.await?;

owner
.call(&worker, wnear.id(), "storage_deposit")
.args_json(serde_json::json!({}))?
.args_json(serde_json::json!({}))
.deposit(parse_near!("0.008 N"))
.transact()
.await?;
Expand Down Expand Up @@ -105,7 +105,7 @@ async fn create_pool_with_liquidity(

ref_finance
.call(worker, "extend_whitelisted_tokens")
.args_json(serde_json::json!({ "tokens": token_ids }))?
.args_json(serde_json::json!({ "tokens": token_ids }))
.transact()
.await?;

Expand All @@ -114,7 +114,7 @@ async fn create_pool_with_liquidity(
.args_json(serde_json::json!({
"tokens": token_ids,
"fee": 25
}))?
}))
.deposit(parse_near!("3 mN"))
.transact()
.await?
Expand All @@ -124,7 +124,7 @@ async fn create_pool_with_liquidity(
.call(&worker, ref_finance.id(), "register_tokens")
.args_json(serde_json::json!({
"token_ids": token_ids,
}))?
}))
.deposit(1)
.transact()
.await?;
Expand All @@ -136,7 +136,7 @@ async fn create_pool_with_liquidity(
.args_json(serde_json::json!({
"pool_id": pool_id,
"amounts": token_amounts,
}))?
}))
.deposit(parse_near!("1 N"))
.transact()
.await?;
Expand All @@ -157,7 +157,7 @@ async fn deposit_tokens(
.call(&worker, contract_id, "storage_deposit")
.args_json(serde_json::json!({
"registration_only": true,
}))?
}))
.deposit(parse_near!("1 N"))
.transact()
.await?;
Expand All @@ -168,7 +168,7 @@ async fn deposit_tokens(
"receiver_id": ref_finance.id(),
"amount": amount.to_string(),
"msg": "",
}))?
}))
.gas(parse_gas!("200 Tgas") as u64)
.deposit(1)
.transact()
Expand All @@ -193,7 +193,7 @@ async fn create_custom_ft(
.args_json(serde_json::json!({
"owner_id": owner.id(),
"total_supply": parse_near!("1,000,000,000 N").to_string(),
}))?
}))
.transact()
.await?;

Expand Down Expand Up @@ -318,7 +318,7 @@ async fn main() -> anyhow::Result<()> {
"amount_in": parse_near!("1 N").to_string(),
"min_amount_out": "1",
})],
}))?
}))
.deposit(1)
.gas(parse_gas!("100 Tgas") as u64)
.transact()
Expand Down
2 changes: 1 addition & 1 deletion examples/src/spooning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn deploy_status_contract(
.call(worker, "set_status")
.args_json(serde_json::json!({
"message": msg,
}))?
}))
.transact()
.await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/src/status_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async fn main() -> anyhow::Result<()> {
.call(&worker, "set_status")
.args_json(json!({
"message": "hello_world",
}))?
}))
.transact()
.await?;
println!("set_status: {:?}", outcome);
Expand Down
1 change: 1 addition & 0 deletions workspaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rand = "0.8.4"
reqwest = { version = "0.11", features = ["json"] }
serde = "1.0"
serde_json = "1.0"
thiserror = "1.0"
tokio = { version = "1", features = ["full"] }
tokio-retry = "0.3"
tracing = "0.1"
Expand Down
Loading