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

fix(spells): allow empty args for callbackSrv [NET-651] #1942

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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(())
}
}
Loading