Skip to content

Add a more helpful error message when Javy.JSON is missing #22

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

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

nickwesselman
Copy link
Contributor

If you use the latest @shopify/shopify_function without the latest Shopify CLI, you get an unhelpful error message:

Error:3:31 cannot read property 'fromStdin' of undefined
    at run_default (function.mjs:3:31)
    at run2 (function.mjs:21:10)
    at <anonymous> (eval_script:1:37)

Several partners have encountered this. This PR makes the output error more helpful.

In the non-error case, this adds 1727 instructions, which is only 0.0157% of the overall budget. Tested cases with the OOTB checkout validation function are below.

CLI 3.66 with shopify_function 1.0.2

npx @shopify/[email protected] app build
echo '{ "cart": { "lines":[] } }' | npx @shopify/[email protected] app function run

Instructions: 165.997K

Error:3:31 cannot read property 'fromStdin' of undefined
    at run_default (function.mjs:3:31)
    at run2 (function.mjs:21:10)
    at <anonymous> (eval_script:1:37)

error while executing at wasm backtrace:
    0: 0x10611b - javy_quickjs_provider.wasm!abort
    1: 0x3e3e8 - javy_quickjs_provider.wasm!std::sys::pal::wasi::helpers::abort_internal::hfbe314d302b73e09
    2: 0x30847 - javy_quickjs_provider.wasm!std::process::abort::hc61a197fac268dc4
    3: 0x30efe - javy_quickjs_provider.wasm!invoke
    4: 0x110ba1 - javy_quickjs_provider.wasm!invoke.command_export
    5:  0x11f - <unknown>!<wasm function 3>

CLI 3.66 with shopify_function changes

  "dependencies": {
    "@shopify/shopify_function": "/Users/nickwesselman/src/shopify-function-javascript"
  }

npx @shopify/[email protected] app build
echo '{ "cart": { "lines":[] } }' | npx @shopify/[email protected] app function run

Instructions: 165.963K

Error:4:11 Javy.JSON is not defined. Please rebuild your function using the latest version of Shopify CLI.
    at run_default (function.mjs:4:11)
    at run2 (function.mjs:24:10)
    at <anonymous> (eval_script:1:37)

error while executing at wasm backtrace:
    0: 0x10611b - javy_quickjs_provider.wasm!abort
    1: 0x3e3e8 - javy_quickjs_provider.wasm!std::sys::pal::wasi::helpers::abort_internal::hfbe314d302b73e09
    2: 0x30847 - javy_quickjs_provider.wasm!std::process::abort::hc61a197fac268dc4
    3: 0x30efe - javy_quickjs_provider.wasm!invoke
    4: 0x110ba1 - javy_quickjs_provider.wasm!invoke.command_export
    5:  0x11f - <unknown>!<wasm function 3>

CLI 3.70 with shopify_function 1.0.2

npx @shopify/cli@latest app build
echo '{ "cart": { "lines":[] } }' | npx @shopify/cli@latest app function run

Instructions: 161.376K

{
  "errors": []
}

CLI 3.70 with shopify_function changes

  "dependencies": {
    "@shopify/shopify_function": "/Users/nickwesselman/src/shopify-function-javascript"
  }

npx @shopify/cli@latest app build
echo '{ "cart": { "lines":[] } }' | npx @shopify/cli@latest app function run

Instructions: 163.103K (+1727)

{
  "errors": []
}

@@ -14,6 +14,9 @@ declare global {
}

export default function <I extends {}, O extends {}>(userfunction: ShopifyFunction<I, O>) {
if (!Javy.JSON) {
throw new Error('Javy.JSON is not defined. Please rebuild your function using the latest version of Shopify CLI.');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to put the exact command you'd need to run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command will depend on if you are using global or local install of the CLI, and your package manager of choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could link to docs, but i worry about that link becoming stale --

https://shopify.dev/docs/api/shopify-cli#upgrade

Copy link
Member

@saulecabrera saulecabrera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@nickwesselman nickwesselman merged commit 6408f21 into main Dec 5, 2024
1 check passed
@nickwesselman nickwesselman deleted the javy-json-check branch December 5, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants