From 3a4a145735acea6132f4c10b7e588ee95b2ad97d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 3 Mar 2026 02:41:58 +0000 Subject: [PATCH] chore: implement consistent logging strategy and translate error messages - Added `info`, `warn`, and `error` logging utilities to `src/utils.ts`. - Replaced direct `console.error`, `console.warn`, and `console.info` usage with the new utilities across the codebase. - Added localization for the `currentVersionInfo` parsing error. - Renamed shadowed `error` variable in `src/core.ts` to `err`. Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com> --- src/client.ts | 3 ++- src/core.ts | 10 +++++----- src/locales/en.ts | 1 + src/locales/zh.ts | 1 + src/utils.ts | 14 +++++++++++++- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/client.ts b/src/client.ts index 48ad5d1b..0106b823 100644 --- a/src/client.ts +++ b/src/client.ts @@ -22,6 +22,7 @@ import { assertWeb, emptyObj, enhancedFetch, + info, joinUrls, log, noop, @@ -189,7 +190,7 @@ export class Pushy { }; assertDebug = (matter: string) => { if (__DEV__ && !this.options.debug) { - console.info(this.t('dev_debug_disabled', { matter })); + info(this.t('dev_debug_disabled', { matter })); return false; } return true; diff --git a/src/core.ts b/src/core.ts index 713c9793..fed1fcb1 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,5 +1,6 @@ import { NativeEventEmitter, NativeModules, Platform } from 'react-native'; -import { emptyModule, log } from './utils'; +import { emptyModule, error, log } from './utils'; +import i18n from './i18n'; const { version: v, } = require('react-native/Libraries/Core/ReactNativeVersion'); @@ -46,10 +47,9 @@ if (currentVersionInfoString) { delete _currentVersionInfo.debugChannel; setLocalHashInfo(currentVersion, _currentVersionInfo); } - } catch (error) { - console.error( - 'Failed to parse currentVersionInfo:', - currentVersionInfoString, + } catch (err) { + error( + i18n.t('error_parse_version_info', { info: currentVersionInfoString }), ); } } diff --git a/src/locales/en.ts b/src/locales/en.ts index 1b0a4575..c80078be 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -44,6 +44,7 @@ export default { // Error messages error_appkey_required: 'appKey is required', + error_parse_version_info: 'Failed to parse currentVersionInfo: {{info}}', error_update_check_failed: 'Update check failed', error_cannot_connect_server: 'Can not connect to update server. Please check your network.', diff --git a/src/locales/zh.ts b/src/locales/zh.ts index 9fefd29a..44291aa5 100644 --- a/src/locales/zh.ts +++ b/src/locales/zh.ts @@ -42,6 +42,7 @@ export default { // Error messages error_appkey_required: '需要提供 appKey', + error_parse_version_info: '解析 currentVersionInfo 失败: {{info}}', error_update_check_failed: '更新检查失败', error_cannot_connect_server: '无法连接到更新服务器。请检查网络连接。', error_cannot_connect_backup: diff --git a/src/utils.ts b/src/utils.ts index e5f9b2a8..752c07c7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,6 +5,18 @@ export function log(...args: any[]) { console.log(i18n.t('dev_log_prefix'), ...args); } +export function info(...args: any[]) { + console.info(i18n.t('dev_log_prefix'), ...args); +} + +export function warn(...args: any[]) { + console.warn(i18n.t('dev_log_prefix'), ...args); +} + +export function error(...args: any[]) { + console.error(i18n.t('dev_log_prefix'), ...args); +} + export const isWeb = Platform.OS === 'web'; export function promiseAny(promises: Promise[]) { @@ -93,7 +105,7 @@ export const testUrls = async (urls?: string[]) => { export const assertWeb = () => { if (isWeb) { - console.warn(i18n.t('dev_web_not_supported')); + warn(i18n.t('dev_web_not_supported')); return false; } return true;