mdn / interactive-examples

Home of the MDN live code editor interactive examples
Creative Commons Zero v1.0 Universal
725 stars 506 forks source link

fix: `Intl.getCanonicalLocales` error message #2741

Closed btea closed 6 months ago

btea commented 6 months ago

Description

Motivation

Additional details

Related issues and pull requests

github-actions[bot] commented 6 months ago

It looks like this is your first pull request. 🎉 Thank you for your contribution! One of the project maintainers will triage and assign the pull request for review. We appreciate your patience. To safeguard the health of the project, please take a moment to read our code of conduct.

bsmth commented 6 months ago

Thanks a lot for raising this one. I'm going to close, however, because I get the following:

image

The error message here is browser-specific so it's safe enough to leave as-is.

Thanks!

btea commented 6 months ago

@bsmth Is it because of the browser difference? The error message I get is as follows:

image

The browser version I am using is Edge 121.0.2277.128.

bsmth commented 6 months ago

Yes, I can confirm if you try it with Chrome, you get the following:

> Array ["en-US"]
> Array ["en-US", "fr"]
> "RangeError: Incorrect locale information provided"

And Safari:

> Array ["en-US"]
> Array ["en-US", "fr"]
> "RangeError: invalid language tag: EN_US"
btea commented 6 months ago

The error messages of Firefox and Safari are consistent, and the output messages of Chrome and node are consistent. Maybe add both error messages and then mark the running environment?

bsmth commented 6 months ago

We can add both to cover Chrome, Fx and Safari, why not. This can also be verified using eshost

'Intl.getCanonicalLocales("EN_US")'
┌──────────────┬───────────────────────────────────────────────────┐
│ SpiderMonkey │                                                   │
│              │ RangeError: invalid language tag: "EN_US"         │
├──────────────┼───────────────────────────────────────────────────┤
│ V8           │                                                   │
│              │ RangeError: Incorrect locale information provided │
└──────────────┴───────────────────────────────────────────────────┘

mark the running environment

The running environment is the reader's browser in this case, so I don't think we need to do anything else there.

Josh-Cena commented 6 months ago

Do we do this elsewhere?

I don't care much for these examples but I also don't think it's helpful when the message has the same meaning anyway.

bsmth commented 6 months ago

Do we do this elsewhere?

We do have a few:

live-examples/js-examples/intl/intl-listformat-prototype-resolvedoptions.js:// Expected output (Chrome): "de"
live-examples/js-examples/intl/intl-numberformat-prototype-resolvedoptions.js:// Expected output (Chrome): "de"
live-examples/js-examples/weakset/weakset-prototype-add.js:  // Expected output (Chrome): TypeError: Invalid value used in weak set
live-examples/js-examples/symbol/symbol-match.js:// Expected output (Chrome): Error: First argument to String.prototype.startsWith must not be a regular expression

And actually I just spotted we have this in the style guide: https://github.com/mdn/interactive-examples/blob/main/contributing/javascript-style-guide.md#representing-browser-differences

I also don't think it's helpful when the message has the same meaning anyway

I tend to agree somewhat, my initial decision was to close for this reason, but I can see why some readers might be confused. I would format it like the suggestion in the style guide and merge, unless you have objections, @Josh-Cena.

Josh-Cena commented 6 months ago

That "browser difference" is actual runtime difference, but this one is just a representational difference. I don't have strong objections, though.

bsmth commented 6 months ago

That "browser difference" is actual runtime difference, but this one is just a representational difference. I don't have strong objections, though.

You're right. Let's go with this for now 👍🏻

github-actions[bot] commented 6 months ago

Congratulations on your first merged pull request. 🎉 Thank you for your contribution! Did you know we have a project board with high-impact contribution opportunities? We look forward to your next contribution.