Shopify / cli

Build apps, themes, and hydrogen storefronts for Shopify
https://shopify.dev
MIT License
377 stars 112 forks source link

[Bug]: Unhandled rejection in telemetry #3867

Open frandiox opened 2 months ago

frandiox commented 2 months ago

Please confirm that you have:

In which of these areas are you experiencing a problem?

Hydrogen custom storefront

Expected behavior

Errors in internal telemetry should not be shown as unhandled rejections. The error should be caught and printed nicely, and maybe only as a debug log.

Actual behavior

For example, when running without internet connection, the following log shows up in the console when running a CLI command (e.g. shopify hydrogen dev):

Unhandled Rejection:  Error: getaddrinfo ENOTFOUND otlp-http-production-cli.shopifysvc.com
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'otlp-http-production-cli.shopifysvc.com'
}

Verbose output

2024-05-08T00:34:21.293Z: Request to https://monorail-edge.shopifysvc.com/v1/produce completed in 6 ms
With response headers:

2024-05-08T00:34:21.293Z: Failed to report usage analytics: request to https://monorail-edge.shopifysvc.com/v1/produce failed, reason: getaddrinfo ENOTFOUND monorail-edge.shopifysvc.com
2024-05-08T00:34:21.293Z: Completed command hydrogen dev
Unhandled Rejection:  Error: getaddrinfo ENOTFOUND otlp-http-production-cli.shopifysvc.com
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'otlp-http-production-cli.shopifysvc.com'
}

Reproduction steps

  1. Run a command without internet connection

Operating System

Mac OS Sonoma 14

Shopify CLI version (check your project's package.json if you're not sure)

3.59.2

Shell

zsh

Node version (run node -v if you're not sure)

v18.7.1

What language and version are you using in your application?

No response

gonzaloriestra commented 1 month ago

Hi, thanks for reporting!

I'm not able to reproduce. I tried by disabling the internet connection, but I can't see any telemetry error. For example, with hydrogen dev, I only get this one:

╭─ warning ───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                         │
│  Failed to fetch Hydrogen changelog                                                                                     │
│                                                                                                                         │
│  Ensure you have internet connection and try again                                                                      │
│                                                                                                                         │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Looking at the code, it seems that we are already catching errors and printing only to debug log: https://github.com/Shopify/cli/blob/95945c4f2c6df3e055a436e75e90cc37d872bc60/packages/cli-kit/src/public/node/analytics.ts#L84

I've also updated the CLI code to always throw an error when reporting analytics, but it only shows the expected debug log.

github-actions[bot] commented 5 days ago

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

P.S. You can learn more about why we stale issues here.