Skip to content

Commit

Permalink
bug: fix hc scaffold link type issues (#368)
Browse files Browse the repository at this point in the history
* fix hardcoded case in check_case function

* fix app crash on scaffolding link_type with target set to [None]
  • Loading branch information
c12i authored Sep 17, 2024
1 parent 01494b6 commit d2f5b69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/scaffold/link_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn scaffold_link_type(

let link_type = match to_referenceable.clone() {
Some(to_referenceable) => link_type_name(&from_referenceable, &to_referenceable),
None => input_with_case(&String::from("Enter link type name:"), Case::Pascal)?,
None => input_with_case("Enter link type name:", Case::Pascal)?,
};

let bidirectional = match (&to_referenceable, bidirectional) {
Expand Down
8 changes: 5 additions & 3 deletions src/scaffold/link_type/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn metadata_handlers(
link_type_name: &str,
from_referenceable: &Referenceable,
) -> TokenStream {
let integrity_zome_name = format_ident!("{}", integrity_zome_name);
let snake_from_arg = format_ident!(
"{}",
from_referenceable
Expand Down Expand Up @@ -77,11 +78,11 @@ fn metadata_handlers(
let links = get_links(
GetLinksInputBuilder::try_new(#snake_from_arg, LinkTypes::#pascal_link_type_name)?.build(),
)?;
let #snake_link_type_name: Vec<String> = links
let #snake_link_type_name = links
.into_iter()
.map(|link|
String::from_utf8(link.tag.into_inner())
.map_err(|e| wasm_error!(WasmErrorInner::Guest(format!("Error converting link tag to string: {{:?}}", e))))
.map_err(|e| wasm_error!(WasmErrorInner::Guest(format!("Error converting link tag to string: {:?}", e))))
)
.collect::<ExternResult<Vec<String>>>()?;
Ok(#snake_link_type_name)
Expand Down Expand Up @@ -474,15 +475,16 @@ pub fn add_link_type_functions_to_coordinator(
let mut file_tree = coordinator_zome_file_tree.dna_file_tree.file_tree();

let handlers = match to_referenceable {
None => metadata_handlers(integrity_zome_name, link_type_name, from_referenceable),
Some(r) => normal_handlers(
integrity_zome_name,
from_referenceable,
r,
delete,
bidirectional,
),
None => metadata_handlers(integrity_zome_name, link_type_name, from_referenceable),
};

let file = unparse_pretty(&syn::parse_quote! { #handlers });

insert_file(&mut file_tree, &new_file_path, &file)?;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn input_no_whitespace(prompt: &str) -> ScaffoldResult<String> {
pub fn check_case(input: &str, identifier: &str, case: Case) -> ScaffoldResult<()> {
if !input.is_case(case) {
return Err(ScaffoldError::InvalidStringFormat(format!(
"{identifier} must be snake_case",
"{identifier} must be {case:?} Case",
)));
}
Ok(())
Expand Down

0 comments on commit d2f5b69

Please sign in to comment.