Wasm validation failed: failed to parse WebAssembly module

  [                                                                                      
    {                                                                                     
      "field": null,                                                                       
      "message": "Wasm validation failed: failed to parse WebAssembly module",             β”‚
      "tag": "user_error"                                                                  
    }                                                                                     
  ]  

Facing this error when trying to deploy shopify app that has an extension written in rust.

Mainly the issue arises when using reqwest module, even on installation of reqwest module it is showing the above error.

use shopify_function::prelude::*;
use shopify_function::Result;

use serde::{Serialize, Deserialize};
// use serde_json::json;

// use reqwest::Client;

generate_types!(
    query_path = "./input.graphql",
    schema_path = "./schema.graphql"
);

#[derive(Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all(deserialize = "camelCase"))]
struct Configuration {

}

impl Configuration {
    fn from_str(value: &str) -> Self {
        serde_json::from_str(value).expect("Unable to parse configuration value from metafield")
    }
}

// async fn get_discount_details(email: &str, order_value: f64) -> Result<()> {
//     let host = "https://httpbin.org";
//     let path = "/post";

//     let url = format!("{}{}", host, path);

//     let client = Client::new();

//     let mut res = client
//         .post(&url)
//         .json(&json!({
//             "key": "value",
//             "array": [1, 2, 3],
//             "object": {
//                 "nested": "objects",
//                 "email": email,
//                 "order_value": order_value
//             }
//         }))
//         .send().await?;

//     eprintln!("{}", res.text().await?);

//     Ok(())

// }

#[shopify_function]
fn function(input: input::ResponseData) -> Result<output::FunctionResult> {
    let no_discount = output::FunctionResult {
        discounts: vec![],
        discount_application_strategy: output::DiscountApplicationStrategy::FIRST,
    };

    eprintln!("input: {:?}", input);

    let buyer = match input.cart.buyer_identity {
        Some(identity) => identity,
        None => return Ok(no_discount),
    };

    eprintln!("buyer: {:?}", buyer);

    let subtotal_amount = input.cart.cost.subtotal_amount.amount.parse::<f64>().unwrap();

    // let discount_amount = get_discount_details(&buyer.email, subtotal_amount);
    // let discount_amount = discount_amount.parse::<f64>().unwrap();

    // if discount_amount == 0.0 {
    //     return Ok(no_discount);
    // }

    let discount_amount = subtotal_amount * 0.1;

    Ok(output::FunctionResult {
        discounts: vec![output::Discount {
            message: Some("10% off for using CDC coins".to_string()),
            conditions: None,
            targets: vec![output::Target {
                order_subtotal: Some(output::OrderSubtotalTarget {
                    excluded_variant_ids: vec![],
                }),
                product_variant: None,
            }],
            value: output::Value {
                fixed_amount: Some(output::FixedAmount {
                    amount: discount_amount.to_string()
                }),
                percentage: None,
            },
        }],
        discount_application_strategy: output::DiscountApplicationStrategy::FIRST,
    })
}

#[cfg(test)]
mod tests;

It looks like Shopify does not allow using any crates that allow HTTP calls within a function.

https://community.shopify.com/post/1788179

By changing the checkout in this manner and forcing us to use functions they have basically nerfed the checkout for any β€œreal” customizations outside of their limited scope which the development team has thought of.