Skip to content

Commit

Permalink
fix(spells): allow empty args for callbackSrv [NET-651] (#1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
justprosh committed Dec 13, 2023
1 parent 21515a5 commit 19e00be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
12 changes: 9 additions & 3 deletions crates/nox-tests/tests/spells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,20 @@ async fn spell_return_test() {
(call %init_peer_id% ("callbackSrv" "response") [obj])
(seq
(seq
(call %init_peer_id% (spell_id "get_string") ["key"] value_raw)
(call %init_peer_id% ("json" "parse") [value_raw.$.str] value)
(seq
(call %init_peer_id% (spell_id "get_string") ["key"] value_raw)
(call %init_peer_id% ("json" "parse") [value_raw.$.str] value)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [])
(call "{}" ("return" "") ["callbackSrv response failed"])
)
)
(call "{}" ("return" "") [value])
)
)
)"#,
client.peer_id
client.peer_id, client.peer_id,
);

let config = make_clock_config(1, 1, 0);
Expand Down
23 changes: 14 additions & 9 deletions sorcerer/src/spell_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,18 @@ pub(crate) fn store_response(
spell_service_api: SpellServiceApi,
) -> Result<(), JError> {
let spell_id = parse_spell_id_from(&params)?;
let response: JValue = Args::next("spell_id", &mut args.function_args.into_iter())?;
let call_params = CallParams::from(spell_id.clone(), params);
spell_service_api
.update_kv(call_params, response.clone())
.map_err(|err| {
JError::new(format!(
"Failed to store response {response} for spell {spell_id}: {err}"
))
})
let response: Option<JValue> = Args::next_opt("response", &mut args.function_args.into_iter())?;

if let Some(response) = response {
let call_params = CallParams::from(spell_id.clone(), params);
spell_service_api
.update_kv(call_params, response.clone())
.map_err(|err| {
JError::new(format!(
"Failed to store response {response} for spell {spell_id}: {err}"
))
})
} else {
Ok(())
}
}

0 comments on commit 19e00be

Please sign in to comment.