From 61b4b840664e9d584afd7b4204fed86bb4a9f593 Mon Sep 17 00:00:00 2001 From: Craig Cornelius Date: Mon, 6 Jan 2025 15:18:07 -0800 Subject: [PATCH] Node errors for locale display names to 'unsupported' (#319) * Node errors for locale display names to 'unsupported' * Set node locale names errors to unsupported * NodeJS: set unsupported locales for locale display names * Adding info to error messages * Set display language problem to unsupported --- executors/node/localedisplaynames.js | 58 ++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/executors/node/localedisplaynames.js b/executors/node/localedisplaynames.js index fe73937e..de4bfbd3 100644 --- a/executors/node/localedisplaynames.js +++ b/executors/node/localedisplaynames.js @@ -4,37 +4,68 @@ module.exports = { testLocaleDisplayNames: function (json) { let locale = 'en'; // Default - let options = {}; if (json['locale_label']) { // Fix to use dash, not underscore. locale = json['locale_label'].replace(/_/g, '-'); } - // options = json['options']; - options = {type: 'language', languageDisplay: 'standard'}; + // Standard for this type of testing. + let options = {type: 'language', + languageDisplay: 'standard', + style: 'long'}; + let label = json['label']; let input = json['language_label'].replace(/_/g, '-'); + let outputLine = { + "label": json['label'], + "locale_label": locale, + "language_label": input, + }; + + try { + const supported_locales = + Intl.DisplayNames.supportedLocalesOf([locale]); + } catch (error) { + // Something wrong with the locale for this + outputLine["error_detail"] = locale + outputLine["error_type"] = 'unsupported locale'; + outputLine["unsupported"] = error.toString(); + return outputLine; + } + + // Check the language to be formatted + try { + let language_label_locale = new Intl.Locale(input); + } catch (error) { + // Something wrong with the locale for this + outputLine["error_detail"] = input; + outputLine["error_type"] = 'Problem with language label'; + outputLine["unsupported"] = error.toString(); + outputLine["actual_options"] = JSON.stringify(options); + return outputLine; + } if (json['languageDisplay']) { - // Fix to use dash, not underscore. options['languageDisplay'] = json['languageDisplay']; } - let outputLine; - let dn; try { dn = new Intl.DisplayNames([locale], options); } catch (error) { outputLine = { "error": error.toString(), - "label": json['label'], "locale_label": locale, - "language_label": input, - "test_type": "display_names", - "error_type": "unsupported", + "error_detail": "Bad constructor for locale: " + locale + ' ' + options, "error_retry": false // Do not repeat }; + if (error instanceof RangeError) { + // The locale can't be handled for some reason! + outputLine["error_type"] = 'unsupported'; + outputLine["unsupported"] = error.toString(); + outputLine["error_detail"] = locale; + outputLine["actual_options"] = JSON.stringify(options); + } return outputLine; } @@ -45,12 +76,15 @@ module.exports = { "result": resultString }; } catch (error) { + const error_string = error.toString(); outputLine = {"label": json['label'], "locale_label": locale, "language_label": input, "result": resultString, - "error": error.toString(), - "actual_options": options.toString() + "error_type": 'unsupported', + "unsupported": error.toString(), + "error_detail": input, + "actual_options": JSON.stringify(options) }; } return outputLine;