diff --git a/src/ctl/mod.rs b/src/ctl/mod.rs index a7263112..8288fa69 100644 --- a/src/ctl/mod.rs +++ b/src/ctl/mod.rs @@ -463,6 +463,20 @@ pub(crate) async fn handle_command(command: CtlCliCommand) -> Result { .link_name .clone() .unwrap_or_else(|| "default".to_string()); + // Check if the contract ID parameter is a 56 character key and suggest that the user + // give the contract ID instead + // + // NOTE: `len` is ok here because keys are only ascii characters that take up a single + // byte. + if cmd.contract_id.len() == 56 && cmd.contract_id.starts_with('V') { + link_del_output( + &cmd.actor_id, + &cmd.contract_id, + link_name, + Some("It looks like you used a Provider ID (e.g. VABC...) instead of a contract ID (e.g. wasmcloud:httpserver)".into()), + &cmd.output.kind, + )?; + } sp = update_spinner_message( sp, format!( @@ -480,7 +494,7 @@ pub(crate) async fn handle_command(command: CtlCliCommand) -> Result { link_name, failure, &cmd.output.kind, - ) + )? } Link(LinkCommand::Put(cmd)) => { sp = update_spinner_message( diff --git a/src/ctl/output.rs b/src/ctl/output.rs index 193511ec..aec74a90 100644 --- a/src/ctl/output.rs +++ b/src/ctl/output.rs @@ -33,21 +33,21 @@ pub(crate) fn link_del_output( link_name: &str, failure: Option, output_kind: &OutputKind, -) -> String { +) -> std::result::Result { match failure { - None => format_output( + None => Ok(format_output( format!( "\nDeleted link for {} on {} ({}) successfully", actor_id, contract_id, link_name ), json!({"actor_id": actor_id, "contract_id": contract_id, "link_name": link_name, "result": "published"}), output_kind, - ), - Some(f) => format_output( + )), + Some(f) => Err(format_output( format!("\nError deleting link: {}", f), json!({ "error": f }), output_kind, - ), + )), } }