diff --git a/src/Analytics.tsx b/src/Analytics.tsx index fc4664039f..5db8c95a84 100644 --- a/src/Analytics.tsx +++ b/src/Analytics.tsx @@ -23,6 +23,8 @@ import SdkConfig from './SdkConfig'; import Modal from './Modal'; import * as sdk from './index'; +import { logger } from "matrix-js-sdk/src/logger"; + const hashRegex = /#\/(groups?|room|user|settings|register|login|forgot_password|home|directory)/; const hashVarRegex = /#\/(group|room|user)\/.*$/; @@ -156,7 +158,7 @@ function getUid(): string { } return data; } catch (e) { - console.error("Analytics error: ", e); + logger.error("Analytics error: ", e); return ""; } } @@ -299,7 +301,7 @@ export class Analytics { redirect: "follow", }); } catch (e) { - console.error("Analytics error: ", e); + logger.error("Analytics error: ", e); } } diff --git a/src/BasePlatform.ts b/src/BasePlatform.ts index 5b4b15cc67..f3b26ec510 100644 --- a/src/BasePlatform.ts +++ b/src/BasePlatform.ts @@ -28,6 +28,8 @@ import { hideToast as hideUpdateToast } from "./toasts/UpdateToast"; import { MatrixClientPeg } from "./MatrixClientPeg"; import { idbLoad, idbSave, idbDelete } from "./utils/StorageManager"; +import { logger } from "matrix-js-sdk/src/logger"; + export const SSO_HOMESERVER_URL_KEY = "mx_sso_hs_url"; export const SSO_ID_SERVER_URL_KEY = "mx_sso_is_url"; export const SSO_IDP_ID_KEY = "mx_sso_idp_id"; @@ -320,7 +322,7 @@ export default abstract class BasePlatform { return null; } if (!data.encrypted || !data.iv || !data.cryptoKey) { - console.error("Badly formatted pickle key"); + logger.error("Badly formatted pickle key"); return null; } @@ -340,7 +342,7 @@ export default abstract class BasePlatform { ); return encodeUnpaddedBase64(key); } catch (e) { - console.error("Error decrypting pickle key"); + logger.error("Error decrypting pickle key"); return null; } } diff --git a/src/CallHandler.tsx b/src/CallHandler.tsx index bc9ccc4bcd..30171aca89 100644 --- a/src/CallHandler.tsx +++ b/src/CallHandler.tsx @@ -444,7 +444,7 @@ export default class CallHandler extends EventEmitter { if (!this.matchesCallForThisRoom(call)) return; Analytics.trackEvent('voip', 'callError', 'error', err.toString()); - console.error("Call error:", err); + logger.error("Call error:", err); if (err.code === CallErrorCode.NoUserMedia) { this.showMediaCaptureError(call); @@ -777,7 +777,7 @@ export default class CallHandler extends EventEmitter { } else if (type === 'video') { call.placeVideoCall(); } else { - console.error("Unknown conf call type: " + type); + logger.error("Unknown conf call type: " + type); } } @@ -811,7 +811,7 @@ export default class CallHandler extends EventEmitter { const room = MatrixClientPeg.get().getRoom(payload.room_id); if (!room) { - console.error(`Room ${payload.room_id} does not exist.`); + logger.error(`Room ${payload.room_id} does not exist.`); return; } @@ -1112,7 +1112,7 @@ export default class CallHandler extends EventEmitter { description: _t("You do not have permission to start a conference call in this room"), }); } - console.error(e); + logger.error(e); }); } diff --git a/src/ContentMessages.tsx b/src/ContentMessages.tsx index 60242b373a..2f9b17a89b 100644 --- a/src/ContentMessages.tsx +++ b/src/ContentMessages.tsx @@ -559,7 +559,7 @@ export default class ContentMessages { Object.assign(content.info, imageInfo); resolve(); }, (e) => { - console.error(e); + logger.error(e); content.msgtype = 'm.file'; resolve(); }); diff --git a/src/CountlyAnalytics.ts b/src/CountlyAnalytics.ts index aa47d3063f..af26a4fbc3 100644 --- a/src/CountlyAnalytics.ts +++ b/src/CountlyAnalytics.ts @@ -25,6 +25,8 @@ import { MatrixClientPeg } from "./MatrixClientPeg"; import RoomViewStore from "./stores/RoomViewStore"; import { Action } from "./dispatcher/actions"; +import { logger } from "matrix-js-sdk/src/logger"; + const INACTIVITY_TIME = 20; // seconds const HEARTBEAT_INTERVAL = 5_000; // ms const SESSION_UPDATE_INTERVAL = 60; // seconds @@ -651,7 +653,7 @@ export default class CountlyAnalytics { body: params, }); } catch (e) { - console.error("Analytics error: ", e); + logger.error("Analytics error: ", e); } } diff --git a/src/Lifecycle.ts b/src/Lifecycle.ts index 3685f7b938..dc7a0e5252 100644 --- a/src/Lifecycle.ts +++ b/src/Lifecycle.ts @@ -234,8 +234,8 @@ export function attemptTokenLogin( } }, }); - console.error("Failed to log in with login token:"); - console.error(err); + logger.error("Failed to log in with login token:"); + logger.error(err); return false; }); } @@ -297,7 +297,7 @@ function registerAsGuest( guest: true, }, true).then(() => true); }, (err) => { - console.error("Failed to register as guest", err); + logger.error("Failed to register as guest", err); return false; }); } @@ -452,7 +452,7 @@ export async function restoreFromLocalStorage(opts?: { ignoreGuest?: boolean }): } async function handleLoadSessionFailure(e: Error): Promise { - console.error("Unable to load session", e); + logger.error("Unable to load session", e); const modal = Modal.createTrackedDialog('Session Restore Error', '', SessionRestoreErrorDialog, { error: e.message, @@ -676,7 +676,7 @@ async function persistCredentials(credentials: IMatrixClientCreds): Promise { - console.error(err.stack); + logger.error(err.stack); Modal.createTrackedDialog('Failed to invite', '', ErrorDialog, { title: _t("Failed to invite"), description: ((err && err.message) ? err.message : _t("Operation failed")), diff --git a/src/ScalarMessaging.ts b/src/ScalarMessaging.ts index d068c1f924..47a5dff94b 100644 --- a/src/ScalarMessaging.ts +++ b/src/ScalarMessaging.ts @@ -272,7 +272,7 @@ function sendResponse(event: MessageEvent, res: any): void { } function sendError(event: MessageEvent, msg: string, nestedError?: Error): void { - console.error("Action:" + event.data.action + " failed with message: " + msg); + logger.error("Action:" + event.data.action + " failed with message: " + msg); const data = objectClone(event.data); data.response = { error: { @@ -721,7 +721,7 @@ export function stopListening(): void { "ScalarMessaging: mismatched startListening / stopListening detected." + " Negative count", ); - console.error(e); + logger.error(e); } } diff --git a/src/SecurityManager.ts b/src/SecurityManager.ts index 925b023584..af1a481409 100644 --- a/src/SecurityManager.ts +++ b/src/SecurityManager.ts @@ -399,7 +399,7 @@ export async function accessSecretStorage(func = async () => { }, forceReset = f return await func(); } catch (e) { SecurityCustomisations.catchAccessSecretStorageError?.(e); - console.error(e); + logger.error(e); // Re-throw so that higher level logic can abort as needed throw e; } finally { diff --git a/src/actions/RoomListActions.ts b/src/actions/RoomListActions.ts index a7f629c40d..d248197f7f 100644 --- a/src/actions/RoomListActions.ts +++ b/src/actions/RoomListActions.ts @@ -27,6 +27,8 @@ import { SortAlgorithm } from "../stores/room-list/algorithms/models"; import { DefaultTagID } from "../stores/room-list/models"; import ErrorDialog from '../components/views/dialogs/ErrorDialog'; +import { logger } from "matrix-js-sdk/src/logger"; + export default class RoomListActions { /** * Creates an action thunk that will do an asynchronous request to @@ -88,7 +90,7 @@ export default class RoomListActions { return Rooms.guessAndSetDMRoom( room, newTag === DefaultTagID.DM, ).catch((err) => { - console.error("Failed to set direct chat tag " + err); + logger.error("Failed to set direct chat tag " + err); Modal.createTrackedDialog('Failed to set direct chat tag', '', ErrorDialog, { title: _t('Failed to set direct chat tag'), description: ((err && err.message) ? err.message : _t('Operation failed')), @@ -108,7 +110,7 @@ export default class RoomListActions { const promiseToDelete = matrixClient.deleteRoomTag( roomId, oldTag, ).catch(function(err) { - console.error("Failed to remove tag " + oldTag + " from room: " + err); + logger.error("Failed to remove tag " + oldTag + " from room: " + err); Modal.createTrackedDialog('Failed to remove tag from room', '', ErrorDialog, { title: _t('Failed to remove tag %(tagName)s from room', { tagName: oldTag }), description: ((err && err.message) ? err.message : _t('Operation failed')), @@ -127,7 +129,7 @@ export default class RoomListActions { metaData = metaData || {}; const promiseToAdd = matrixClient.setRoomTag(roomId, newTag, metaData).catch(function(err) { - console.error("Failed to add tag " + newTag + " to room: " + err); + logger.error("Failed to add tag " + newTag + " to room: " + err); Modal.createTrackedDialog('Failed to add tag to room', '', ErrorDialog, { title: _t('Failed to add tag %(tagName)s to room', { tagName: newTag }), description: ((err && err.message) ? err.message : _t('Operation failed')), diff --git a/src/async-components/views/dialogs/security/CreateKeyBackupDialog.js b/src/async-components/views/dialogs/security/CreateKeyBackupDialog.js index 2cef1c0e41..8527f78895 100644 --- a/src/async-components/views/dialogs/security/CreateKeyBackupDialog.js +++ b/src/async-components/views/dialogs/security/CreateKeyBackupDialog.js @@ -26,6 +26,8 @@ import AccessibleButton from "../../../../components/views/elements/AccessibleBu import { copyNode } from "../../../../utils/strings"; import PassphraseField from "../../../../components/views/auth/PassphraseField"; +import { logger } from "matrix-js-sdk/src/logger"; + const PHASE_PASSPHRASE = 0; const PHASE_PASSPHRASE_CONFIRM = 1; const PHASE_SHOWKEY = 2; @@ -129,7 +131,7 @@ export default class CreateKeyBackupDialog extends React.PureComponent { phase: PHASE_DONE, }); } catch (e) { - console.error("Error creating key backup", e); + logger.error("Error creating key backup", e); // TODO: If creating a version succeeds, but backup fails, should we // delete the version, disable backup, or do nothing? If we just // disable without deleting, we'll enable on next app reload since diff --git a/src/async-components/views/dialogs/security/CreateSecretStorageDialog.js b/src/async-components/views/dialogs/security/CreateSecretStorageDialog.js index 5fbc97d2f1..7a21b7075b 100644 --- a/src/async-components/views/dialogs/security/CreateSecretStorageDialog.js +++ b/src/async-components/views/dialogs/security/CreateSecretStorageDialog.js @@ -349,7 +349,7 @@ export default class CreateSecretStorageDialog extends React.PureComponent { } else { this.setState({ error: e }); } - console.error("Error bootstrapping secret storage", e); + logger.error("Error bootstrapping secret storage", e); } } diff --git a/src/async-components/views/dialogs/security/ExportE2eKeysDialog.js b/src/async-components/views/dialogs/security/ExportE2eKeysDialog.js index dbed9f3968..c21e17a7a1 100644 --- a/src/async-components/views/dialogs/security/ExportE2eKeysDialog.js +++ b/src/async-components/views/dialogs/security/ExportE2eKeysDialog.js @@ -23,6 +23,8 @@ import { MatrixClient } from 'matrix-js-sdk/src/client'; import * as MegolmExportEncryption from '../../../../utils/MegolmExportEncryption'; import * as sdk from '../../../../index'; +import { logger } from "matrix-js-sdk/src/logger"; + const PHASE_EDIT = 1; const PHASE_EXPORTING = 2; @@ -83,7 +85,7 @@ export default class ExportE2eKeysDialog extends React.Component { FileSaver.saveAs(blob, 'element-keys.txt'); this.props.onFinished(true); }).catch((e) => { - console.error("Error exporting e2e keys:", e); + logger.error("Error exporting e2e keys:", e); if (this._unmounted) { return; } diff --git a/src/async-components/views/dialogs/security/ImportE2eKeysDialog.js b/src/async-components/views/dialogs/security/ImportE2eKeysDialog.js index 0936ad696d..51d2861396 100644 --- a/src/async-components/views/dialogs/security/ImportE2eKeysDialog.js +++ b/src/async-components/views/dialogs/security/ImportE2eKeysDialog.js @@ -22,6 +22,8 @@ import * as MegolmExportEncryption from '../../../../utils/MegolmExportEncryptio import * as sdk from '../../../../index'; import { _t } from '../../../../languageHandler'; +import { logger } from "matrix-js-sdk/src/logger"; + function readFileAsArrayBuffer(file) { return new Promise((resolve, reject) => { const reader = new FileReader(); @@ -91,7 +93,7 @@ export default class ImportE2eKeysDialog extends React.Component { // TODO: it would probably be nice to give some feedback about what we've imported here. this.props.onFinished(true); }).catch((e) => { - console.error("Error importing e2e keys:", e); + logger.error("Error importing e2e keys:", e); if (this._unmounted) { return; } diff --git a/src/audio/Playback.ts b/src/audio/Playback.ts index 9ad4c85df5..7e62daab56 100644 --- a/src/audio/Playback.ts +++ b/src/audio/Playback.ts @@ -156,18 +156,18 @@ export class Playback extends EventEmitter implements IDestroyable { try { // This error handler is largely for Safari as well, which doesn't support Opus/Ogg // very well. - console.error("Error decoding recording: ", e); + logger.error("Error decoding recording: ", e); console.warn("Trying to re-encode to WAV instead..."); const wav = await decodeOgg(this.buf); // noinspection ES6MissingAwait - not needed when using callbacks this.context.decodeAudioData(wav, b => resolve(b), e => { - console.error("Still failed to decode recording: ", e); + logger.error("Still failed to decode recording: ", e); reject(e); }); } catch (e) { - console.error("Caught decoding error:", e); + logger.error("Caught decoding error:", e); reject(e); } }); diff --git a/src/audio/VoiceRecording.ts b/src/audio/VoiceRecording.ts index 67b2acda0c..3ff02be774 100644 --- a/src/audio/VoiceRecording.ts +++ b/src/audio/VoiceRecording.ts @@ -32,6 +32,8 @@ import { FixedRollingArray } from "../utils/FixedRollingArray"; import { clamp } from "../utils/numbers"; import mxRecorderWorkletPath from "./RecorderWorklet"; +import { logger } from "matrix-js-sdk/src/logger"; + const CHANNELS = 1; // stereo isn't important export const SAMPLE_RATE = 48000; // 48khz is what WebRTC uses. 12khz is where we lose quality. const BITRATE = 24000; // 24kbps is pretty high quality for our use case in opus. @@ -171,9 +173,9 @@ export class VoiceRecording extends EventEmitter implements IDestroyable { this.buffer = newBuf; }; } catch (e) { - console.error("Error starting recording: ", e); + logger.error("Error starting recording: ", e); if (e instanceof DOMException) { // Unhelpful DOMExceptions are common - parse them sanely - console.error(`${e.name} (${e.code}): ${e.message}`); + logger.error(`${e.name} (${e.code}): ${e.message}`); } // Clean up as best as possible diff --git a/src/components/structures/FilePanel.tsx b/src/components/structures/FilePanel.tsx index 77629839d9..c57c2f7ecf 100644 --- a/src/components/structures/FilePanel.tsx +++ b/src/components/structures/FilePanel.tsx @@ -39,6 +39,8 @@ import { TileShape } from '../views/rooms/EventTile'; import { Layout } from "../../settings/Layout"; import RoomContext, { TimelineRenderingType } from '../../contexts/RoomContext'; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { roomId: string; onClose: () => void; @@ -210,10 +212,10 @@ class FilePanel extends React.Component { this.setState({ timelineSet: timelineSet }); } catch (error) { - console.error("Failed to get or create file panel filter", error); + logger.error("Failed to get or create file panel filter", error); } } else { - console.error("Failed to add filtered timelineSet for FilePanel as no room!"); + logger.error("Failed to add filtered timelineSet for FilePanel as no room!"); } } diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js index f4f1d50d63..298fa0a4b6 100644 --- a/src/components/structures/GroupView.js +++ b/src/components/structures/GroupView.js @@ -45,6 +45,8 @@ import { createSpaceFromCommunity } from "../../utils/space"; import { Action } from "../../dispatcher/actions"; import { RightPanelPhases } from "../../stores/RightPanelStorePhases"; +import { logger } from "matrix-js-sdk/src/logger"; + const LONG_DESC_PLACEHOLDER = _td( `

HTML for your community's page

@@ -186,7 +188,7 @@ class FeaturedRoom extends React.Component { this.props.groupId, this.props.summaryInfo.room_id, ).catch((err) => { - console.error('Error whilst removing room from group summary', err); + logger.error('Error whilst removing room from group summary', err); const roomName = this.props.summaryInfo.name || this.props.summaryInfo.canonical_alias || this.props.summaryInfo.room_id; @@ -352,7 +354,7 @@ class FeaturedUser extends React.Component { this.props.groupId, this.props.summaryInfo.user_id, ).catch((err) => { - console.error('Error whilst removing user from group summary', err); + logger.error('Error whilst removing user from group summary', err); const displayName = this.props.summaryInfo.displayname || this.props.summaryInfo.user_id; const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); Modal.createTrackedDialog( @@ -551,7 +553,7 @@ export default class GroupView extends React.Component { }, }); }).catch((e) => { - console.error('Error getting group inviter profile', e); + logger.error('Error getting group inviter profile', e); }).finally(() => { if (this._unmounted) return; this.setState({ @@ -641,7 +643,7 @@ export default class GroupView extends React.Component { }).catch((e) => { this.setState({ uploadingAvatar: false }); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - console.error("Failed to upload avatar image", e); + logger.error("Failed to upload avatar image", e); Modal.createTrackedDialog('Failed to upload image', '', ErrorDialog, { title: _t('Error'), description: _t('Failed to upload image'), @@ -675,7 +677,7 @@ export default class GroupView extends React.Component { saving: false, }); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - console.error("Failed to save community profile", e); + logger.error("Failed to save community profile", e); Modal.createTrackedDialog('Failed to update group', '', ErrorDialog, { title: _t('Error'), description: _t('Failed to update community'), @@ -1421,7 +1423,7 @@ export default class GroupView extends React.Component { ); } } else { - console.error("Invalid state for GroupView"); + logger.error("Invalid state for GroupView"); return

; } } diff --git a/src/components/structures/InteractiveAuth.tsx b/src/components/structures/InteractiveAuth.tsx index 970ea26309..36489ac4a0 100644 --- a/src/components/structures/InteractiveAuth.tsx +++ b/src/components/structures/InteractiveAuth.tsx @@ -29,6 +29,8 @@ import getEntryComponentForLoginType, { IStageComponent } from '../views/auth/In import Spinner from "../views/elements/Spinner"; import { replaceableComponent } from "../../utils/replaceableComponent"; +import { logger } from "matrix-js-sdk/src/logger"; + export const ERROR_USER_CANCELLED = new Error("User cancelled auth session"); interface IProps { @@ -137,7 +139,7 @@ export default class InteractiveAuthComponent extends React.Component { this.props.onAuthFinished(false, error); - console.error("Error during user-interactive auth:", error); + logger.error("Error during user-interactive auth:", error); if (this.unmounted) { return; } diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index d649c702bc..13eca3265a 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -1580,7 +1580,7 @@ export default class MatrixChat extends React.PureComponent { newVersionInfo = await MatrixClientPeg.get().getKeyBackupVersion(); if (newVersionInfo !== null) haveNewVersion = true; } catch (e) { - console.error("Saw key backup error but failed to check backup version!", e); + logger.error("Saw key backup error but failed to check backup version!", e); return; } } @@ -2121,7 +2121,7 @@ export default class MatrixChat extends React.PureComponent { /> ); } else { - console.error(`Unknown view ${this.state.view}`); + logger.error(`Unknown view ${this.state.view}`); } return diff --git a/src/components/structures/NotificationPanel.tsx b/src/components/structures/NotificationPanel.tsx index c37eeca091..52046c1855 100644 --- a/src/components/structures/NotificationPanel.tsx +++ b/src/components/structures/NotificationPanel.tsx @@ -26,6 +26,8 @@ import { TileShape } from "../views/rooms/EventTile"; import { Layout } from "../../settings/Layout"; import RoomContext, { TimelineRenderingType } from "../../contexts/RoomContext"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { onClose(): void; } @@ -59,7 +61,7 @@ export default class NotificationPanel extends React.PureComponent { /> ); } else { - console.error("No notifTimelineSet available!"); + logger.error("No notifTimelineSet available!"); content = ; } diff --git a/src/components/structures/RoomDirectory.tsx b/src/components/structures/RoomDirectory.tsx index 3c5f99cc7d..8e9be29103 100644 --- a/src/components/structures/RoomDirectory.tsx +++ b/src/components/structures/RoomDirectory.tsx @@ -48,6 +48,8 @@ import Spinner from "../views/elements/Spinner"; import { ActionPayload } from "../../dispatcher/payloads"; import { getDisplayAliasForAliasSet } from "../../Rooms"; +import { logger } from "matrix-js-sdk/src/logger"; + const MAX_NAME_LENGTH = 80; const MAX_TOPIC_LENGTH = 800; @@ -285,7 +287,7 @@ export default class RoomDirectory extends React.Component { return false; } - console.error("Failed to get publicRooms: %s", JSON.stringify(err)); + logger.error("Failed to get publicRooms: %s", JSON.stringify(err)); track('Failed to get public room list'); const brand = SdkConfig.get().brand; this.setState({ @@ -335,7 +337,7 @@ export default class RoomDirectory extends React.Component { }, (err) => { modal.close(); this.refreshRoomList(); - console.error("Failed to " + step + ": " + err); + logger.error("Failed to " + step + ": " + err); Modal.createTrackedDialog('Remove from Directory Error', '', ErrorDialog, { title: _t('Error'), description: (err && err.message) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index e5067f1fcf..51404a17d9 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -963,8 +963,8 @@ export class RoomView extends React.Component { } catch (err) { const errorMessage = `Fetching room members for ${room.roomId} failed.` + " Room members will appear incomplete."; - console.error(errorMessage); - console.error(err); + logger.error(errorMessage); + logger.error(err); } } } @@ -1315,7 +1315,7 @@ export class RoomView extends React.Component { return searchPromise.then((results) => { debuglog("search complete"); if (this.unmounted || !this.state.searching || this.searchId != localSearchId) { - console.error("Discarding stale search results"); + logger.error("Discarding stale search results"); return false; } @@ -1341,7 +1341,7 @@ export class RoomView extends React.Component { searchResults: results, }); }, (error) => { - console.error("Search failed", error); + logger.error("Search failed", error); Modal.createTrackedDialog('Search failed', '', ErrorDialog, { title: _t("Search failed"), description: ((error && error.message) ? error.message : @@ -1472,7 +1472,7 @@ export class RoomView extends React.Component { rejecting: false, }); }, (error) => { - console.error("Failed to reject invite: %s", error); + logger.error("Failed to reject invite: %s", error); const msg = error.message ? error.message : JSON.stringify(error); Modal.createTrackedDialog('Failed to reject invite', '', ErrorDialog, { @@ -1505,7 +1505,7 @@ export class RoomView extends React.Component { rejecting: false, }); } catch (error) { - console.error("Failed to reject invite: %s", error); + logger.error("Failed to reject invite: %s", error); const msg = error.message ? error.message : JSON.stringify(error); Modal.createTrackedDialog('Failed to reject invite', '', ErrorDialog, { diff --git a/src/components/structures/ScrollPanel.tsx b/src/components/structures/ScrollPanel.tsx index 0ea070627a..1699b535d9 100644 --- a/src/components/structures/ScrollPanel.tsx +++ b/src/components/structures/ScrollPanel.tsx @@ -408,7 +408,7 @@ export default class ScrollPanel extends React.Component { try { await Promise.all(fillPromises); } catch (err) { - console.error(err); + logger.error(err); } } if (isFirstCall) { diff --git a/src/components/structures/SpaceRoomView.tsx b/src/components/structures/SpaceRoomView.tsx index 383524b738..423bcdd305 100644 --- a/src/components/structures/SpaceRoomView.tsx +++ b/src/components/structures/SpaceRoomView.tsx @@ -536,7 +536,7 @@ const SpaceSetupFirstRooms = ({ space, title, description, onFinished }) => { })); onFinished(roomIds[0]); } catch (e) { - console.error("Failed to create initial space rooms", e); + logger.error("Failed to create initial space rooms", e); setError(_t("Failed to create initial space rooms")); } setBusy(false); @@ -713,7 +713,7 @@ const SpaceSetupPrivateInvite = ({ space, onFinished }) => { onFinished(); } } catch (err) { - console.error("Failed to invite users to space: ", err); + logger.error("Failed to invite users to space: ", err); setError(_t("We couldn't invite those users. Please check the users you want to invite and try again.")); } setBusy(false); diff --git a/src/components/structures/TabbedView.tsx b/src/components/structures/TabbedView.tsx index 037c33a600..efa1143443 100644 --- a/src/components/structures/TabbedView.tsx +++ b/src/components/structures/TabbedView.tsx @@ -23,6 +23,8 @@ import { replaceableComponent } from "../../utils/replaceableComponent"; import classNames from "classnames"; import AccessibleButton from "../views/elements/AccessibleButton"; +import { logger } from "matrix-js-sdk/src/logger"; + /** * Represents a tab for the TabbedView. */ @@ -90,7 +92,7 @@ export default class TabbedView extends React.Component { if (this.props.onChange) this.props.onChange(tab.id); this.setState({ activeTabIndex: idx }); } else { - console.error("Could not find tab " + tab.label + " in tabs"); + logger.error("Could not find tab " + tab.label + " in tabs"); } } diff --git a/src/components/structures/TimelinePanel.tsx b/src/components/structures/TimelinePanel.tsx index 6924181132..e07a27cf04 100644 --- a/src/components/structures/TimelinePanel.tsx +++ b/src/components/structures/TimelinePanel.tsx @@ -799,11 +799,11 @@ class TimelinePanel extends React.Component { lastReadEvent, {}, ).catch((e) => { - console.error(e); + logger.error(e); this.lastRRSentEventId = undefined; }); } else { - console.error(e); + logger.error(e); } // it failed, so allow retries next time the user is active this.lastRRSentEventId = undefined; @@ -1121,7 +1121,7 @@ class TimelinePanel extends React.Component { if (this.unmounted) return; this.setState({ timelineLoading: false }); - console.error( + logger.error( `Error loading timeline panel at ${eventId}: ${error}`, ); diff --git a/src/components/structures/auth/ForgotPassword.tsx b/src/components/structures/auth/ForgotPassword.tsx index 24b47bfa03..2cb2a2a1a9 100644 --- a/src/components/structures/auth/ForgotPassword.tsx +++ b/src/components/structures/auth/ForgotPassword.tsx @@ -33,6 +33,8 @@ import { PASSWORD_MIN_SCORE } from '../../views/auth/RegistrationForm'; import { IValidationResult } from "../../views/elements/Validation"; import InlineSpinner from '../../views/elements/InlineSpinner'; +import { logger } from "matrix-js-sdk/src/logger"; + enum Phase { // Show the forgot password inputs Forgot = 1, @@ -147,7 +149,7 @@ export default class ForgotPassword extends React.Component { private onVerify = async (ev: React.MouseEvent): Promise => { ev.preventDefault(); if (!this.reset) { - console.error("onVerify called before submitPasswordReset!"); + logger.error("onVerify called before submitPasswordReset!"); return; } if (this.state.currentHttpRequest) return; diff --git a/src/components/structures/auth/Login.tsx b/src/components/structures/auth/Login.tsx index c8f208476b..403c013e64 100644 --- a/src/components/structures/auth/Login.tsx +++ b/src/components/structures/auth/Login.tsx @@ -309,7 +309,7 @@ export default class LoginComponent extends React.PureComponent busy: false, }); } catch (e) { - console.error("Problem parsing URL or unhandled error doing .well-known discovery:", e); + logger.error("Problem parsing URL or unhandled error doing .well-known discovery:", e); let message = _t("Failed to perform homeserver discovery"); if (e.translatedMessage) { diff --git a/src/components/structures/auth/Registration.tsx b/src/components/structures/auth/Registration.tsx index 4cffed4348..3c66a1ab86 100644 --- a/src/components/structures/auth/Registration.tsx +++ b/src/components/structures/auth/Registration.tsx @@ -195,7 +195,7 @@ export default class Registration extends React.Component { const loginFlows = await this.loginLogic.getFlows(); ssoFlow = loginFlows.find(f => f.type === "m.login.sso" || f.type === "m.login.cas") as ISSOFlow; } catch (e) { - console.error("Failed to get login flows to check for SSO support", e); + logger.error("Failed to get login flows to check for SSO support", e); } this.setState({ @@ -370,12 +370,12 @@ export default class Registration extends React.Component { matrixClient.setPusher(emailPusher).then(() => { logger.log("Set email branding to " + this.props.brand); }, (error) => { - console.error("Couldn't set email branding: " + error); + logger.error("Couldn't set email branding: " + error); }); } } }, (error) => { - console.error("Couldn't get pushers: " + error); + logger.error("Couldn't get pushers: " + error); }); } diff --git a/src/components/structures/auth/SoftLogout.tsx b/src/components/structures/auth/SoftLogout.tsx index a943f47e66..db93d30c27 100644 --- a/src/components/structures/auth/SoftLogout.tsx +++ b/src/components/structures/auth/SoftLogout.tsx @@ -173,7 +173,7 @@ export default class SoftLogout extends React.Component { } Lifecycle.hydrateSession(credentials).catch((e) => { - console.error(e); + logger.error(e); this.setState({ busy: false, errorText: _t("Failed to re-authenticate") }); }); }; @@ -193,7 +193,7 @@ export default class SoftLogout extends React.Component { try { credentials = await sendLoginRequest(hsUrl, isUrl, loginType, loginParams); } catch (e) { - console.error(e); + logger.error(e); this.setState({ busy: false, loginView: LOGIN_VIEW.UNSUPPORTED }); return; } @@ -201,7 +201,7 @@ export default class SoftLogout extends React.Component { Lifecycle.hydrateSession(credentials).then(() => { if (this.props.onTokenLoginCompleted) this.props.onTokenLoginCompleted(); }).catch((e) => { - console.error(e); + logger.error(e); this.setState({ busy: false, loginView: LOGIN_VIEW.UNSUPPORTED }); }); } diff --git a/src/components/views/audio_messages/AudioPlayerBase.tsx b/src/components/views/audio_messages/AudioPlayerBase.tsx index d8fc9d507f..5158e87827 100644 --- a/src/components/views/audio_messages/AudioPlayerBase.tsx +++ b/src/components/views/audio_messages/AudioPlayerBase.tsx @@ -21,6 +21,8 @@ import { UPDATE_EVENT } from "../../../stores/AsyncStore"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import { _t } from "../../../languageHandler"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { // Playback instance to render. Cannot change during component lifecycle: create // an all-new component instead. @@ -50,7 +52,7 @@ export default abstract class AudioPlayerBase extends React.PureComponent { - console.error("Error processing audio file:", e); + logger.error("Error processing audio file:", e); this.setState({ error: true }); }); } diff --git a/src/components/views/auth/CaptchaForm.tsx b/src/components/views/auth/CaptchaForm.tsx index db0e07e046..5820b9335b 100644 --- a/src/components/views/auth/CaptchaForm.tsx +++ b/src/components/views/auth/CaptchaForm.tsx @@ -85,13 +85,13 @@ export default class CaptchaForm extends React.Component { static defaultProps = { - onValidationChange: console.error, + onValidationChange: logger.error, canSubmit: true, }; diff --git a/src/components/views/avatars/MemberAvatar.tsx b/src/components/views/avatars/MemberAvatar.tsx index 001df16d40..48b2575cd2 100644 --- a/src/components/views/avatars/MemberAvatar.tsx +++ b/src/components/views/avatars/MemberAvatar.tsx @@ -25,6 +25,8 @@ import BaseAvatar from "./BaseAvatar"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import { mediaFromMxc } from "../../../customisations/Media"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps extends Omit, "name" | "idName" | "url"> { member: RoomMember; fallbackUserId?: string; @@ -85,7 +87,7 @@ export default class MemberAvatar extends React.Component { title: props.fallbackUserId, }; } else { - console.error("MemberAvatar called somehow with null member or fallbackUserId"); + logger.error("MemberAvatar called somehow with null member or fallbackUserId"); } } diff --git a/src/components/views/context_menus/GroupInviteTileContextMenu.js b/src/components/views/context_menus/GroupInviteTileContextMenu.js index 1529723ac8..ed5a45d432 100644 --- a/src/components/views/context_menus/GroupInviteTileContextMenu.js +++ b/src/components/views/context_menus/GroupInviteTileContextMenu.js @@ -25,6 +25,8 @@ import GroupStore from "../../../stores/GroupStore"; import { MenuItem } from "../../structures/ContextMenu"; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import { logger } from "matrix-js-sdk/src/logger"; + @replaceableComponent("views.context_menus.GroupInviteTileContextMenu") export default class GroupInviteTileContextMenu extends React.Component { static propTypes = { @@ -62,7 +64,7 @@ export default class GroupInviteTileContextMenu extends React.Component { try { await GroupStore.leaveGroup(this.props.group.groupId); } catch (e) { - console.error("Error rejecting community invite: ", e); + logger.error("Error rejecting community invite: ", e); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); Modal.createTrackedDialog('Error rejecting invite', '', ErrorDialog, { title: _t("Error"), diff --git a/src/components/views/context_menus/WidgetContextMenu.tsx b/src/components/views/context_menus/WidgetContextMenu.tsx index 26d7b640a4..0c3b1dd788 100644 --- a/src/components/views/context_menus/WidgetContextMenu.tsx +++ b/src/components/views/context_menus/WidgetContextMenu.tsx @@ -34,6 +34,8 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext"; import { Container, WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore"; import { getConfigLivestreamUrl, startJitsiAudioLivestream } from "../../../Livestream"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps extends React.ComponentProps { app: IApp; userWidget?: boolean; @@ -65,7 +67,7 @@ const WidgetContextMenu: React.FC = ({ try { await startJitsiAudioLivestream(widgetMessaging, roomId); } catch (err) { - console.error("Failed to start livestream", err); + logger.error("Failed to start livestream", err); // XXX: won't i18n well, but looks like widget api only support 'message'? const message = err.message || _t("Unable to start audio streaming."); Modal.createTrackedDialog('WidgetContext Menu', 'Livestream failed', ErrorDialog, { @@ -114,7 +116,7 @@ const WidgetContextMenu: React.FC = ({ file: data.screenshot, }); }).catch(err => { - console.error("Failed to take screenshot: ", err); + logger.error("Failed to take screenshot: ", err); }); onFinished(); }; @@ -165,7 +167,7 @@ const WidgetContextMenu: React.FC = ({ current[app.eventId] = false; const level = SettingsStore.firstSupportedLevel("allowedWidgets"); SettingsStore.setValue("allowedWidgets", roomId, level, current).catch(err => { - console.error(err); + logger.error(err); // We don't really need to do anything about this - the user will just hit the button again. }); onFinished(); diff --git a/src/components/views/dialogs/AddExistingToSpaceDialog.tsx b/src/components/views/dialogs/AddExistingToSpaceDialog.tsx index 01a767bf14..337941ce5f 100644 --- a/src/components/views/dialogs/AddExistingToSpaceDialog.tsx +++ b/src/components/views/dialogs/AddExistingToSpaceDialog.tsx @@ -41,6 +41,8 @@ import TruncatedList from "../elements/TruncatedList"; import EntityTile from "../rooms/EntityTile"; import BaseAvatar from "../avatars/BaseAvatar"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { space: Room; onCreateRoomClick(): void; @@ -160,7 +162,7 @@ export const AddExistingToSpace: React.FC = ({ }); setProgress(i => i + 1); } catch (e) { - console.error("Failed to add rooms to space", e); + logger.error("Failed to add rooms to space", e); setError(error = e); break; } diff --git a/src/components/views/dialogs/AddressPickerDialog.tsx b/src/components/views/dialogs/AddressPickerDialog.tsx index 6b239ee570..9484859509 100644 --- a/src/components/views/dialogs/AddressPickerDialog.tsx +++ b/src/components/views/dialogs/AddressPickerDialog.tsx @@ -37,6 +37,8 @@ import AddressTile from '../elements/AddressTile'; import BaseDialog from "./BaseDialog"; import DialogButtons from "../elements/DialogButtons"; +import { logger } from "matrix-js-sdk/src/logger"; + const TRUNCATE_QUERY_LIST = 40; const QUERY_USER_DIRECTORY_DEBOUNCE_MS = 200; @@ -225,7 +227,7 @@ export default class AddressPickerDialog extends React.Component this.doRoomSearch(query); } } else { - console.error('Unknown pickerType', this.props.pickerType); + logger.error('Unknown pickerType', this.props.pickerType); } }, QUERY_USER_DIRECTORY_DEBOUNCE_MS); } else { @@ -282,7 +284,7 @@ export default class AddressPickerDialog extends React.Component }); this.processResults(results, query); }).catch((err) => { - console.error('Error whilst searching group rooms: ', err); + logger.error('Error whilst searching group rooms: ', err); this.setState({ searchError: err.errcode ? err.message : _t('Something went wrong!'), }); @@ -388,7 +390,7 @@ export default class AddressPickerDialog extends React.Component } this.processResults(resp.results, query); }).catch((err) => { - console.error('Error whilst searching user directory: ', err); + logger.error('Error whilst searching user directory: ', err); this.setState({ searchError: err.errcode ? err.message : _t('Something went wrong!'), }); @@ -582,7 +584,7 @@ export default class AddressPickerDialog extends React.Component }], }); } catch (e) { - console.error(e); + logger.error(e); this.setState({ searchError: _t('Something went wrong!'), }); diff --git a/src/components/views/dialogs/CommunityPrototypeInviteDialog.tsx b/src/components/views/dialogs/CommunityPrototypeInviteDialog.tsx index 6a8773ce45..d5a54aaa23 100644 --- a/src/components/views/dialogs/CommunityPrototypeInviteDialog.tsx +++ b/src/components/views/dialogs/CommunityPrototypeInviteDialog.tsx @@ -33,6 +33,8 @@ import ErrorDialog from "./ErrorDialog"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import { mediaFromMxc } from "../../../customisations/Media"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps extends IDialogProps { roomId: string; communityName: string; @@ -99,7 +101,7 @@ export default class CommunityPrototypeInviteDialog extends React.PureComponent< } } catch (e) { this.setState({ busy: false }); - console.error(e); + logger.error(e); Modal.createTrackedDialog('Failed to invite', '', ErrorDialog, { title: _t("Failed to invite"), description: ((e && e.message) ? e.message : _t("Operation failed")), diff --git a/src/components/views/dialogs/CreateCommunityPrototypeDialog.tsx b/src/components/views/dialogs/CreateCommunityPrototypeDialog.tsx index ccac45fbcc..ed48778b1d 100644 --- a/src/components/views/dialogs/CreateCommunityPrototypeDialog.tsx +++ b/src/components/views/dialogs/CreateCommunityPrototypeDialog.tsx @@ -27,6 +27,8 @@ import { showCommunityRoomInviteDialog } from "../../../RoomInvite"; import GroupStore from "../../../stores/GroupStore"; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps extends IDialogProps { } @@ -110,7 +112,7 @@ export default class CreateCommunityPrototypeDialog extends React.PureComponent< }); } } catch (e) { - console.error(e); + logger.error(e); this.setState({ busy: false, error: _t( diff --git a/src/components/views/dialogs/CreateSpaceFromCommunityDialog.tsx b/src/components/views/dialogs/CreateSpaceFromCommunityDialog.tsx index c7706c115c..c241855f26 100644 --- a/src/components/views/dialogs/CreateSpaceFromCommunityDialog.tsx +++ b/src/components/views/dialogs/CreateSpaceFromCommunityDialog.tsx @@ -42,6 +42,8 @@ import TagOrderActions from "../../../actions/TagOrderActions"; import { inviteUsersToRoom } from "../../../RoomInvite"; import ProgressBar from "../elements/ProgressBar"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { matrixClient: MatrixClient; groupId: string; @@ -271,7 +273,7 @@ const CreateSpaceFromCommunityDialog: React.FC = ({ matrixClient: cli, g }, }, "mx_CreateSpaceFromCommunityDialog_SuccessInfoDialog"); } catch (e) { - console.error(e); + logger.error(e); setError(e); } diff --git a/src/components/views/dialogs/CreateSubspaceDialog.tsx b/src/components/views/dialogs/CreateSubspaceDialog.tsx index 0d7facb476..44ffd2afdd 100644 --- a/src/components/views/dialogs/CreateSubspaceDialog.tsx +++ b/src/components/views/dialogs/CreateSubspaceDialog.tsx @@ -30,6 +30,8 @@ import { createSpace, SpaceCreateForm } from "../spaces/SpaceCreateMenu"; import { SubspaceSelector } from "./AddExistingToSpaceDialog"; import JoinRuleDropdown from "../elements/JoinRuleDropdown"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { space: Room; onAddExistingSpaceClick(): void; @@ -83,7 +85,7 @@ const CreateSubspaceDialog: React.FC = ({ space, onAddExistingSpaceClick onFinished(true); } catch (e) { - console.error(e); + logger.error(e); } }; diff --git a/src/components/views/dialogs/DeactivateAccountDialog.tsx b/src/components/views/dialogs/DeactivateAccountDialog.tsx index 6548bd78fc..6930f46bb0 100644 --- a/src/components/views/dialogs/DeactivateAccountDialog.tsx +++ b/src/components/views/dialogs/DeactivateAccountDialog.tsx @@ -28,6 +28,8 @@ import StyledCheckbox from "../elements/StyledCheckbox"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import BaseDialog from "./BaseDialog"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { onFinished: (success: boolean) => void; } @@ -112,7 +114,7 @@ export default class DeactivateAccountDialog extends React.Component { - console.error(e); + logger.error(e); this.setState({ errStr: _t("There was a problem communicating with the server. Please try again.") }); }); }; diff --git a/src/components/views/dialogs/EditCommunityPrototypeDialog.tsx b/src/components/views/dialogs/EditCommunityPrototypeDialog.tsx index a0e6046d71..7463c82cfb 100644 --- a/src/components/views/dialogs/EditCommunityPrototypeDialog.tsx +++ b/src/components/views/dialogs/EditCommunityPrototypeDialog.tsx @@ -26,6 +26,8 @@ import FlairStore from "../../../stores/FlairStore"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import { mediaFromMxc } from "../../../customisations/Media"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps extends IDialogProps { communityId: string; } @@ -89,7 +91,7 @@ export default class EditCommunityPrototypeDialog extends React.PureComponent = ({ room, onFinished }) => { ); break; default: - console.error("Unknown export format"); + logger.error("Unknown export format"); return; } }; diff --git a/src/components/views/dialogs/InviteDialog.tsx b/src/components/views/dialogs/InviteDialog.tsx index c9ea1143de..84392c8ba4 100644 --- a/src/components/views/dialogs/InviteDialog.tsx +++ b/src/components/views/dialogs/InviteDialog.tsx @@ -731,7 +731,7 @@ export default class InviteDialog extends React.PureComponent { - console.error("Error searching user directory:"); - console.error(e); + logger.error("Error searching user directory:"); + logger.error(e); this.setState({ serverResultsMixin: [] }); // clear results because it's moderately fatal }); @@ -948,8 +948,8 @@ export default class InviteDialog extends React.PureComponent
; } else { - console.error("Unknown kind of InviteDialog: " + this.props.kind); + logger.error("Unknown kind of InviteDialog: " + this.props.kind); } const goButton = this.props.kind == KIND_CALL_TRANSFER ? null : reject(error)); return promise; diff --git a/src/components/views/dialogs/ServerPickerDialog.tsx b/src/components/views/dialogs/ServerPickerDialog.tsx index 7a79791b3c..4c355c6c0e 100644 --- a/src/components/views/dialogs/ServerPickerDialog.tsx +++ b/src/components/views/dialogs/ServerPickerDialog.tsx @@ -28,6 +28,8 @@ import TextWithTooltip from "../elements/TextWithTooltip"; import withValidation, { IFieldState } from "../elements/Validation"; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { title?: string; serverConfig: ValidatedServerConfig; @@ -93,7 +95,7 @@ export default class ServerPickerDialog extends React.PureComponent { }); }, (err) => { this.setState({ emailBusy: false }); - console.error("Unable to add email address " + emailAddress + " " + err); + logger.error("Unable to add email address " + emailAddress + " " + err); Modal.createTrackedDialog('Unable to add email address', '', ErrorDialog, { title: _t("Unable to add email address"), description: ((err && err.message) ? err.message : _t("Operation failed")), @@ -119,7 +121,7 @@ export default class SetEmailDialog extends React.Component { onFinished: this.onEmailDialogFinished, }); } else { - console.error("Unable to verify email address: " + err); + logger.error("Unable to verify email address: " + err); Modal.createTrackedDialog('Unable to verify email address', '', ErrorDialog, { title: _t("Unable to verify email address."), description: ((err && err.message) ? err.message : _t("Operation failed")), diff --git a/src/components/views/dialogs/TabbedIntegrationManagerDialog.tsx b/src/components/views/dialogs/TabbedIntegrationManagerDialog.tsx index 0f87b5c18d..dab1a1f222 100644 --- a/src/components/views/dialogs/TabbedIntegrationManagerDialog.tsx +++ b/src/components/views/dialogs/TabbedIntegrationManagerDialog.tsx @@ -27,6 +27,8 @@ import AccessibleButton from "../elements/AccessibleButton"; import IntegrationManager from "../settings/IntegrationManager"; import { IDialogProps } from "./IDialogProps"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps extends IDialogProps { /** * Optional room where the integration manager should be open to @@ -116,7 +118,7 @@ export default class TabbedIntegrationManagerDialog extends React.Component { // Fetch a token for the integration manager, now that we're allowed to this.startWidget(); }).catch(err => { - console.error(err); + logger.error(err); // We don't really need to do anything about this - the user will just hit the button again. }); }; diff --git a/src/components/views/elements/ErrorBoundary.tsx b/src/components/views/elements/ErrorBoundary.tsx index 50ea7d9a56..7e8686a35c 100644 --- a/src/components/views/elements/ErrorBoundary.tsx +++ b/src/components/views/elements/ErrorBoundary.tsx @@ -25,6 +25,8 @@ import { replaceableComponent } from "../../../utils/replaceableComponent"; import BugReportDialog from '../dialogs/BugReportDialog'; import AccessibleButton from './AccessibleButton'; +import { logger } from "matrix-js-sdk/src/logger"; + interface IState { error: Error; } @@ -52,8 +54,8 @@ export default class ErrorBoundary extends React.PureComponent<{}, IState> { componentDidCatch(error: Error, { componentStack }: ErrorInfo): void { // Browser consoles are better at formatting output when native errors are passed // in their own `console.error` invocation. - console.error(error); - console.error( + logger.error(error); + logger.error( "The above error occured while React was rendering the following components:", componentStack, ); diff --git a/src/components/views/elements/Flair.js b/src/components/views/elements/Flair.js index 873d65d5bd..280cac503e 100644 --- a/src/components/views/elements/Flair.js +++ b/src/components/views/elements/Flair.js @@ -22,6 +22,8 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import { mediaFromMxc } from "../../../customisations/Media"; +import { logger } from "matrix-js-sdk/src/logger"; + class FlairAvatar extends React.Component { constructor() { super(); @@ -92,7 +94,7 @@ export default class Flair extends React.Component { try { groupProfile = await FlairStore.getGroupProfileCached(this.context, groupId); } catch (err) { - console.error('Could not get profile for group', groupId, err); + logger.error('Could not get profile for group', groupId, err); } profiles.push(groupProfile); } diff --git a/src/components/views/elements/Pill.js b/src/components/views/elements/Pill.js index 95d29fc9ae..4a2b39f891 100644 --- a/src/components/views/elements/Pill.js +++ b/src/components/views/elements/Pill.js @@ -29,6 +29,8 @@ import { mediaFromMxc } from "../../../customisations/Media"; import Tooltip from './Tooltip'; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import { logger } from "matrix-js-sdk/src/logger"; + @replaceableComponent("views.elements.Pill") class Pill extends React.Component { static roomNotifPos(text) { @@ -188,7 +190,7 @@ class Pill extends React.Component { }; this.setState({ member }); }).catch((err) => { - console.error('Could not retrieve profile data for ' + userId + ':', err); + logger.error('Could not retrieve profile data for ' + userId + ':', err); }); } diff --git a/src/components/views/groups/GroupRoomInfo.js b/src/components/views/groups/GroupRoomInfo.js index d8f086700d..b59144a716 100644 --- a/src/components/views/groups/GroupRoomInfo.js +++ b/src/components/views/groups/GroupRoomInfo.js @@ -27,6 +27,8 @@ import AutoHideScrollbar from "../../structures/AutoHideScrollbar"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import { mediaFromMxc } from "../../../customisations/Media"; +import { logger } from "matrix-js-sdk/src/logger"; + @replaceableComponent("views.groups.GroupRoomInfo") export default class GroupRoomInfo extends React.Component { static contextType = MatrixClientContext; @@ -103,7 +105,7 @@ export default class GroupRoomInfo extends React.Component { action: "view_group_room_list", }); }).catch((err) => { - console.error(`Error whilst removing ${roomId} from ${groupId}`, err); + logger.error(`Error whilst removing ${roomId} from ${groupId}`, err); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); Modal.createTrackedDialog('Failed to remove room from group', '', ErrorDialog, { title: _t("Failed to remove room from community"), @@ -133,7 +135,7 @@ export default class GroupRoomInfo extends React.Component { const roomId = this.props.groupRoomId; const roomName = this.state.groupRoom.displayname; GroupStore.updateGroupRoomVisibility(this.props.groupId, roomId, isPublic).catch((err) => { - console.error(`Error whilst changing visibility of ${roomId} in ${groupId} to ${isPublic}`, err); + logger.error(`Error whilst changing visibility of ${roomId} in ${groupId} to ${isPublic}`, err); const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); Modal.createTrackedDialog('Failed to remove room from group', '', ErrorDialog, { title: _t("Something went wrong!"), diff --git a/src/components/views/groups/GroupTile.js b/src/components/views/groups/GroupTile.js index 21308ac056..cf1a5b91ce 100644 --- a/src/components/views/groups/GroupTile.js +++ b/src/components/views/groups/GroupTile.js @@ -26,6 +26,8 @@ import { _t } from "../../../languageHandler"; import TagOrderActions from "../../../actions/TagOrderActions"; import GroupFilterOrderStore from "../../../stores/GroupFilterOrderStore"; +import { logger } from "matrix-js-sdk/src/logger"; + @replaceableComponent("views.groups.GroupTile") class GroupTile extends React.Component { static propTypes = { @@ -51,7 +53,7 @@ class GroupTile extends React.Component { FlairStore.getGroupProfileCached(this.context, this.props.groupId).then((profile) => { this.setState({ profile }); }).catch((err) => { - console.error('Error whilst getting cached profile for GroupTile', err); + logger.error('Error whilst getting cached profile for GroupTile', err); }); } diff --git a/src/components/views/groups/GroupUserSettings.js b/src/components/views/groups/GroupUserSettings.js index efb392c54f..85fd15e238 100644 --- a/src/components/views/groups/GroupUserSettings.js +++ b/src/components/views/groups/GroupUserSettings.js @@ -20,6 +20,8 @@ import { _t } from '../../../languageHandler'; import MatrixClientContext from "../../../contexts/MatrixClientContext"; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import { logger } from "matrix-js-sdk/src/logger"; + @replaceableComponent("views.groups.GroupUserSettings") export default class GroupUserSettings extends React.Component { static contextType = MatrixClientContext; @@ -33,7 +35,7 @@ export default class GroupUserSettings extends React.Component { this.context.getJoinedGroups().then((result) => { this.setState({ groups: result.groups || [], error: null }); }, (err) => { - console.error(err); + logger.error(err); this.setState({ groups: null, error: err }); }); } diff --git a/src/components/views/messages/MKeyVerificationRequest.tsx b/src/components/views/messages/MKeyVerificationRequest.tsx index ce828beed0..e1b91f63d7 100644 --- a/src/components/views/messages/MKeyVerificationRequest.tsx +++ b/src/components/views/messages/MKeyVerificationRequest.tsx @@ -27,6 +27,8 @@ import EventTileBubble from "./EventTileBubble"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import AccessibleButton from '../elements/AccessibleButton'; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { mxEvent: MatrixEvent; } @@ -68,7 +70,7 @@ export default class MKeyVerificationRequest extends React.Component { this.openRequest(); await request.accept(); } catch (err) { - console.error(err.message); + logger.error(err.message); } } }; @@ -79,7 +81,7 @@ export default class MKeyVerificationRequest extends React.Component { try { await request.cancel(); } catch (err) { - console.error(err.message); + logger.error(err.message); } } }; diff --git a/src/components/views/right_panel/PinnedMessagesCard.tsx b/src/components/views/right_panel/PinnedMessagesCard.tsx index c82e5a3f80..bb6ddb0f74 100644 --- a/src/components/views/right_panel/PinnedMessagesCard.tsx +++ b/src/components/views/right_panel/PinnedMessagesCard.tsx @@ -29,6 +29,8 @@ import { useAsyncMemo } from "../../../hooks/useAsyncMemo"; import PinnedEventTile from "../rooms/PinnedEventTile"; import { useRoomState } from "../../../hooks/useRoomState"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { room: Room; onClose(): void; @@ -107,8 +109,8 @@ const PinnedMessagesCard = ({ room, onClose }: IProps) => { return event; } } catch (err) { - console.error("Error looking up pinned event " + eventId + " in room " + room.roomId); - console.error(err); + logger.error("Error looking up pinned event " + eventId + " in room " + room.roomId); + logger.error(err); } return null; }); diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index e73e51bcb8..7d76da71a3 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -582,7 +582,7 @@ const RoomKickButton = ({ room, member, startUpdating, stopUpdating }: Omit = ({ member }) => { await cli.redactEvent(roomId, event.getId()); } catch (err) { // log and swallow errors - console.error("Could not redact", event.getId()); - console.error(err); + logger.error("Could not redact", event.getId()); + logger.error(err); } })); console.info(`Finished redacting recent ${count} messages for ${user} in ${roomId}`); @@ -744,7 +744,7 @@ const BanToggleButton = ({ room, member, startUpdating, stopUpdating }: Omit = ({ member, room, powerLevels, try { if (!(await warnSelfDemote(SpaceStore.spacesEnabled && room?.isSpaceRoom()))) return; } catch (e) { - console.error("Failed to warn about self demotion: ", e); + logger.error("Failed to warn about self demotion: ", e); return; } } @@ -817,7 +817,7 @@ const MuteToggleButton: React.FC = ({ member, room, powerLevels, // get out of sync if we force setState here! logger.log("Mute toggle success"); }, function(err) { - console.error("Mute error: " + err); + logger.error("Mute error: " + err); Modal.createTrackedDialog('Failed to mute user', '', ErrorDialog, { title: _t("Error"), description: _t("Failed to mute user"), @@ -1130,7 +1130,7 @@ const PowerLevelEditor: React.FC<{ // get out of sync if we force setState here! logger.log("Power change success"); }, function(err) { - console.error("Failed to change power level " + err); + logger.error("Failed to change power level " + err); Modal.createTrackedDialog('Failed to change power level', '', ErrorDialog, { title: _t("Error"), description: _t("Failed to change power level"), @@ -1166,7 +1166,7 @@ const PowerLevelEditor: React.FC<{ try { if (!(await warnSelfDemote(SpaceStore.spacesEnabled && room?.isSpaceRoom()))) return; } catch (e) { - console.error("Failed to warn about self demotion: ", e); + logger.error("Failed to warn about self demotion: ", e); } } @@ -1315,8 +1315,8 @@ const BasicUserInfo: React.FC<{ try { await cli.deactivateSynapseUser(member.userId); } catch (err) { - console.error("Failed to deactivate user"); - console.error(err); + logger.error("Failed to deactivate user"); + logger.error(err); Modal.createTrackedDialog('Failed to deactivate Synapse user', '', ErrorDialog, { title: _t('Failed to deactivate user'), diff --git a/src/components/views/right_panel/VerificationPanel.tsx b/src/components/views/right_panel/VerificationPanel.tsx index 8ed56bb2c3..007b5d923c 100644 --- a/src/components/views/right_panel/VerificationPanel.tsx +++ b/src/components/views/right_panel/VerificationPanel.tsx @@ -35,6 +35,8 @@ import { replaceableComponent } from "../../../utils/replaceableComponent"; import AccessibleButton from "../elements/AccessibleButton"; import VerificationShowSas from "../verification/VerificationShowSas"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { layout: string; request: VerificationRequest; @@ -335,7 +337,7 @@ export default class VerificationPanel extends React.PureComponent { MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.canonical_alias", eventContent, "").catch((err) => { - console.error(err); + logger.error(err); Modal.createTrackedDialog('Error updating main address', '', ErrorDialog, { title: _t("Error updating main address"), description: _t( @@ -204,7 +206,7 @@ export default class AliasSettings extends React.Component { MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.canonical_alias", eventContent, "").catch((err) => { - console.error(err); + logger.error(err); Modal.createTrackedDialog('Error updating alternative addresses', '', ErrorDialog, { title: _t("Error updating main address"), description: _t( @@ -236,7 +238,7 @@ export default class AliasSettings extends React.Component { this.changeCanonicalAlias(alias); } }).catch((err) => { - console.error(err); + logger.error(err); Modal.createTrackedDialog('Error creating address', '', ErrorDialog, { title: _t("Error creating address"), description: _t( @@ -259,7 +261,7 @@ export default class AliasSettings extends React.Component { this.changeCanonicalAlias(null); } }).catch((err) => { - console.error(err); + logger.error(err); let description; if (err.errcode === "M_FORBIDDEN") { description = _t("You don't have permission to delete the address."); diff --git a/src/components/views/room_settings/RelatedGroupSettings.js b/src/components/views/room_settings/RelatedGroupSettings.js index 23b497398a..f815cd77cc 100644 --- a/src/components/views/room_settings/RelatedGroupSettings.js +++ b/src/components/views/room_settings/RelatedGroupSettings.js @@ -24,6 +24,8 @@ import ErrorDialog from "../dialogs/ErrorDialog"; import MatrixClientContext from "../../../contexts/MatrixClientContext"; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import { logger } from "matrix-js-sdk/src/logger"; + const GROUP_ID_REGEX = /\+\S+:\S+/; @replaceableComponent("views.room_settings.RelatedGroupSettings") @@ -53,7 +55,7 @@ export default class RelatedGroupSettings extends React.Component { this.context.sendStateEvent(this.props.roomId, 'm.room.related_groups', { groups: newGroupsList, }, '').catch((err) => { - console.error(err); + logger.error(err); Modal.createTrackedDialog('Error updating flair', '', ErrorDialog, { title: _t("Error updating flair"), description: _t( diff --git a/src/components/views/rooms/BasicMessageComposer.tsx b/src/components/views/rooms/BasicMessageComposer.tsx index edf4f515d2..4d13fab190 100644 --- a/src/components/views/rooms/BasicMessageComposer.tsx +++ b/src/components/views/rooms/BasicMessageComposer.tsx @@ -49,6 +49,8 @@ import { ICompletion } from "../../../autocomplete/Autocompleter"; import { AutocompleteAction, getKeyBindingsManager, MessageComposerAction } from '../../../KeyBindingsManager'; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import { logger } from "matrix-js-sdk/src/logger"; + // matches emoticons which follow the start of a line or whitespace const REGEX_EMOTICON_WHITESPACE = new RegExp('(?:^|\\s)(' + EMOTICON_REGEX.source + ')\\s|:^$'); export const REGEX_EMOTICON = new RegExp('(?:^|\\s)(' + EMOTICON_REGEX.source + ')$'); @@ -207,7 +209,7 @@ export default class BasicMessageEditor extends React.Component try { setSelection(this.editorRef.current, this.props.model, selection); } catch (err) { - console.error(err); + logger.error(err); } // if caret selection is a range, take the end position const position = selection instanceof Range ? selection.end : selection; @@ -596,7 +598,7 @@ export default class BasicMessageEditor extends React.Component this.setState({ showVisualBell: true }); } } catch (err) { - console.error(err); + logger.error(err); } } diff --git a/src/components/views/rooms/EditMessageComposer.tsx b/src/components/views/rooms/EditMessageComposer.tsx index 538de9afbf..1e0a367772 100644 --- a/src/components/views/rooms/EditMessageComposer.tsx +++ b/src/components/views/rooms/EditMessageComposer.tsx @@ -251,7 +251,7 @@ class EditMessageComposer extends React.Component partCreator.deserializePart(p)); return parts; } catch (e) { - console.error("Error parsing editing state: ", e); + logger.error("Error parsing editing state: ", e); } } } @@ -329,7 +329,7 @@ class EditMessageComposer extends React.Component a.filter(Boolean)) as Promise<[string, IPreviewUrlResponse][]>; }; diff --git a/src/components/views/rooms/SendMessageComposer.tsx b/src/components/views/rooms/SendMessageComposer.tsx index f35cba3cb9..dbda251c48 100644 --- a/src/components/views/rooms/SendMessageComposer.tsx +++ b/src/components/views/rooms/SendMessageComposer.tsx @@ -358,7 +358,7 @@ export class SendMessageComposer extends React.Component { scalarClient.disableWidgetAssets(WidgetType.STICKERPICKER, this.state.widgetId).then(() => { logger.log('Assets disabled'); }).catch((err) => { - console.error('Failed to disable assets'); + logger.error('Failed to disable assets'); }); } else { - console.error("Cannot disable assets: no scalar client"); + logger.error("Cannot disable assets: no scalar client"); } } else { console.warn('No widget ID specified, not disabling assets'); @@ -120,7 +120,7 @@ export default class Stickerpicker extends React.PureComponent { WidgetUtils.removeStickerpickerWidgets().then(() => { this.forceUpdate(); }).catch((e) => { - console.error('Failed to remove sticker picker widget', e); + logger.error('Failed to remove sticker picker widget', e); }); }; @@ -152,7 +152,7 @@ export default class Stickerpicker extends React.PureComponent { } private imError(errorMsg: string, e: Error): void { - console.error(errorMsg, e); + logger.error(errorMsg, e); this.setState({ imError: _t(errorMsg), }); @@ -230,7 +230,7 @@ export default class Stickerpicker extends React.PureComponent { const messaging = WidgetMessagingStore.instance.getMessagingForId(this.state.stickerpickerWidget.id); if (messaging && visible !== this.prevSentVisibility) { messaging.updateVisibility(visible).catch(err => { - console.error("Error updating widget visibility: ", err); + logger.error("Error updating widget visibility: ", err); }); this.prevSentVisibility = visible; } diff --git a/src/components/views/rooms/ThirdPartyMemberInfo.tsx b/src/components/views/rooms/ThirdPartyMemberInfo.tsx index 1590ce0871..c29c558655 100644 --- a/src/components/views/rooms/ThirdPartyMemberInfo.tsx +++ b/src/components/views/rooms/ThirdPartyMemberInfo.tsx @@ -29,6 +29,8 @@ import ErrorDialog from '../dialogs/ErrorDialog'; import AccessibleButton from '../elements/AccessibleButton'; import SpaceStore from "../../../stores/SpaceStore"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { event: MatrixEvent; } @@ -100,7 +102,7 @@ export default class ThirdPartyMemberInfo extends React.Component { MatrixClientPeg.get().sendStateEvent(this.state.roomId, "m.room.third_party_invite", {}, this.state.stateKey) .catch((err) => { - console.error(err); + logger.error(err); // Revert echo because of error this.setState({ invited: true }); diff --git a/src/components/views/rooms/VoiceRecordComposerTile.tsx b/src/components/views/rooms/VoiceRecordComposerTile.tsx index 288d97fc50..e50672ed4a 100644 --- a/src/components/views/rooms/VoiceRecordComposerTile.tsx +++ b/src/components/views/rooms/VoiceRecordComposerTile.tsx @@ -36,6 +36,8 @@ import { NotificationColor } from "../../../stores/notifications/NotificationCol import InlineSpinner from "../elements/InlineSpinner"; import { PlaybackManager } from "../../../audio/PlaybackManager"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { room: Room; } @@ -75,7 +77,7 @@ export default class VoiceRecordComposerTile extends React.PureComponent { }); } catch (e) { this.setState({ error: e }); - console.error("Error bootstrapping cross-signing", e); + logger.error("Error bootstrapping cross-signing", e); } if (this.unmounted) return; this.getUpdatedStatus(); diff --git a/src/components/views/settings/DevicesPanel.tsx b/src/components/views/settings/DevicesPanel.tsx index d66d0f42eb..c2dc924694 100644 --- a/src/components/views/settings/DevicesPanel.tsx +++ b/src/components/views/settings/DevicesPanel.tsx @@ -28,6 +28,8 @@ import DevicesPanelEntry from "./DevicesPanelEntry"; import Spinner from "../elements/Spinner"; import AccessibleButton from "../elements/AccessibleButton"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { className?: string; } @@ -72,7 +74,7 @@ export default class DevicesPanel extends React.Component { // 404 probably means the HS doesn't yet support the API. errtxt = _t("Your homeserver does not support session management."); } else { - console.error("Error loading sessions:", error); + logger.error("Error loading sessions:", error); errtxt = _t("Unable to load session list"); } this.setState({ deviceLoadError: errtxt }); @@ -159,7 +161,7 @@ export default class DevicesPanel extends React.Component { }, }); }).catch((e) => { - console.error("Error deleting sessions", e); + logger.error("Error deleting sessions", e); if (this.unmounted) { return; } }).finally(() => { this.setState({ diff --git a/src/components/views/settings/DevicesPanelEntry.tsx b/src/components/views/settings/DevicesPanelEntry.tsx index 1131114556..6d73e1fe86 100644 --- a/src/components/views/settings/DevicesPanelEntry.tsx +++ b/src/components/views/settings/DevicesPanelEntry.tsx @@ -24,6 +24,8 @@ import StyledCheckbox from '../elements/StyledCheckbox'; import { replaceableComponent } from "../../../utils/replaceableComponent"; import EditableTextContainer from "../elements/EditableTextContainer"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { device?: IMyDevice; onDeviceToggled?: (device: IMyDevice) => void; @@ -41,7 +43,7 @@ export default class DevicesPanelEntry extends React.Component { return MatrixClientPeg.get().setDeviceDetails(device.device_id, { display_name: value, }).catch((e) => { - console.error("Error setting session display name", e); + logger.error("Error setting session display name", e); throw new Error(_t("Failed to set display name")); }); }; diff --git a/src/components/views/settings/Notifications.tsx b/src/components/views/settings/Notifications.tsx index 2f3f7abe4b..133e9dda77 100644 --- a/src/components/views/settings/Notifications.tsx +++ b/src/components/views/settings/Notifications.tsx @@ -39,6 +39,8 @@ import TagComposer from "../elements/TagComposer"; import { objectClone } from "../../../utils/objects"; import { arrayDiff } from "../../../utils/arrays"; +import { logger } from "matrix-js-sdk/src/logger"; + // TODO: this "view" component still has far too much application logic in it, // which should be factored out to other files. @@ -139,7 +141,7 @@ export default class Notifications extends React.PureComponent { phase: Phase.Ready, }); } catch (e) { - console.error("Error setting up notifications for settings: ", e); + logger.error("Error setting up notifications for settings: ", e); this.setState({ phase: Phase.Error }); } } @@ -264,7 +266,7 @@ export default class Notifications extends React.PureComponent { await this.refreshFromServer(); } catch (e) { this.setState({ phase: Phase.Error }); - console.error("Error updating master push rule:", e); + logger.error("Error updating master push rule:", e); this.showSaveError(); } }; @@ -298,7 +300,7 @@ export default class Notifications extends React.PureComponent { await this.refreshFromServer(); } catch (e) { this.setState({ phase: Phase.Error }); - console.error("Error updating email pusher:", e); + logger.error("Error updating email pusher:", e); this.showSaveError(); } }; @@ -367,7 +369,7 @@ export default class Notifications extends React.PureComponent { await this.refreshFromServer(); } catch (e) { this.setState({ phase: Phase.Error }); - console.error("Error updating push rule:", e); + logger.error("Error updating push rule:", e); this.showSaveError(); } }; @@ -427,7 +429,7 @@ export default class Notifications extends React.PureComponent { await this.refreshFromServer(); } catch (e) { this.setState({ phase: Phase.Error }); - console.error("Error updating keyword push rules:", e); + logger.error("Error updating keyword push rules:", e); this.showSaveError(); } } diff --git a/src/components/views/settings/SecureBackupPanel.tsx b/src/components/views/settings/SecureBackupPanel.tsx index 44c5c44412..d69cf250a6 100644 --- a/src/components/views/settings/SecureBackupPanel.tsx +++ b/src/components/views/settings/SecureBackupPanel.tsx @@ -210,7 +210,7 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> { try { await accessSecretStorage(async () => { }, /* forceReset = */ true); } catch (e) { - console.error("Error resetting secret storage", e); + logger.error("Error resetting secret storage", e); if (this.unmounted) return; this.setState({ error: e }); } diff --git a/src/components/views/settings/SetIdServer.tsx b/src/components/views/settings/SetIdServer.tsx index 1f488f1e67..d7cfc7b83a 100644 --- a/src/components/views/settings/SetIdServer.tsx +++ b/src/components/views/settings/SetIdServer.tsx @@ -32,6 +32,8 @@ import AccessibleButton from '../elements/AccessibleButton'; import Field from '../elements/Field'; import QuestionDialog from "../dialogs/QuestionDialog"; +import { logger } from "matrix-js-sdk/src/logger"; + // We'll wait up to this long when checking for 3PID bindings on the IS. const REACHABILITY_TIMEOUT = 10000; // ms @@ -206,7 +208,7 @@ export default class SetIdServer extends React.Component { this.saveIdServer(fullUrl); } } catch (e) { - console.error(e); + logger.error(e); errStr = _t("Terms of service not accepted or the identity server is invalid."); } } diff --git a/src/components/views/settings/SetIntegrationManager.tsx b/src/components/views/settings/SetIntegrationManager.tsx index e083efae0e..7ecc6d1134 100644 --- a/src/components/views/settings/SetIntegrationManager.tsx +++ b/src/components/views/settings/SetIntegrationManager.tsx @@ -23,6 +23,8 @@ import SettingsStore from "../../../settings/SettingsStore"; import { SettingLevel } from "../../../settings/SettingLevel"; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { } @@ -48,8 +50,8 @@ export default class SetIntegrationManager extends React.Component { const current = this.state.provisioningEnabled; SettingsStore.setValue("integrationProvisioning", null, SettingLevel.ACCOUNT, !current).catch(err => { - console.error("Error changing integration manager provisioning"); - console.error(err); + logger.error("Error changing integration manager provisioning"); + logger.error(err); this.setState({ provisioningEnabled: current }); }); diff --git a/src/components/views/settings/account/EmailAddresses.tsx b/src/components/views/settings/account/EmailAddresses.tsx index df440ebde0..039d20f3e8 100644 --- a/src/components/views/settings/account/EmailAddresses.tsx +++ b/src/components/views/settings/account/EmailAddresses.tsx @@ -27,6 +27,8 @@ import { replaceableComponent } from "../../../../utils/replaceableComponent"; import ErrorDialog from "../../dialogs/ErrorDialog"; import { IThreepid, ThreepidMedium } from "matrix-js-sdk/src/@types/threepids"; +import { logger } from "matrix-js-sdk/src/logger"; + /* TODO: Improve the UX for everything in here. It's very much placeholder, but it gets the job done. The old way of handling @@ -78,7 +80,7 @@ export class ExistingEmailAddress extends React.Component { return this.props.onRemoved(this.props.email); }).catch((err) => { - console.error("Unable to remove contact information: " + err); + logger.error("Unable to remove contact information: " + err); Modal.createTrackedDialog('Remove 3pid failed', '', ErrorDialog, { title: _t("Unable to remove contact information"), description: ((err && err.message) ? err.message : _t("Operation failed")), @@ -181,7 +183,7 @@ export default class EmailAddresses extends React.Component { task.addEmailAddress(email).then(() => { this.setState({ continueDisabled: false }); }).catch((err) => { - console.error("Unable to add email address " + email + " " + err); + logger.error("Unable to add email address " + email + " " + err); this.setState({ verifying: false, continueDisabled: false, addTask: null }); Modal.createTrackedDialog('Unable to add email address', '', ErrorDialog, { title: _t("Unable to add email address"), @@ -221,7 +223,7 @@ export default class EmailAddresses extends React.Component { "and then click continue again."), }); } else { - console.error("Unable to verify email address: ", err); + logger.error("Unable to verify email address: ", err); Modal.createTrackedDialog('Unable to verify email address', '', ErrorDialog, { title: _t("Unable to verify email address."), description: ((err && err.message) ? err.message : _t("Operation failed")), diff --git a/src/components/views/settings/account/PhoneNumbers.tsx b/src/components/views/settings/account/PhoneNumbers.tsx index 9105dfc312..4a380980d8 100644 --- a/src/components/views/settings/account/PhoneNumbers.tsx +++ b/src/components/views/settings/account/PhoneNumbers.tsx @@ -28,6 +28,8 @@ import { IThreepid, ThreepidMedium } from "matrix-js-sdk/src/@types/threepids"; import ErrorDialog from "../../dialogs/ErrorDialog"; import { PhoneNumberCountryDefinition } from "../../../../phonenumber"; +import { logger } from "matrix-js-sdk/src/logger"; + /* TODO: Improve the UX for everything in here. This is a copy/paste of EmailAddresses, mostly. @@ -74,7 +76,7 @@ export class ExistingPhoneNumber extends React.Component { return this.props.onRemoved(this.props.msisdn); }).catch((err) => { - console.error("Unable to remove contact information: " + err); + logger.error("Unable to remove contact information: " + err); Modal.createTrackedDialog('Remove 3pid failed', '', ErrorDialog, { title: _t("Unable to remove contact information"), description: ((err && err.message) ? err.message : _t("Operation failed")), @@ -183,7 +185,7 @@ export default class PhoneNumbers extends React.Component { task.addMsisdn(phoneCountry, phoneNumber).then((response) => { this.setState({ continueDisabled: false, verifyMsisdn: response.msisdn }); }).catch((err) => { - console.error("Unable to add phone number " + phoneNumber + " " + err); + logger.error("Unable to add phone number " + phoneNumber + " " + err); this.setState({ verifying: false, continueDisabled: false, addTask: null }); Modal.createTrackedDialog('Add Phone Number Error', '', ErrorDialog, { title: _t("Error"), @@ -221,7 +223,7 @@ export default class PhoneNumbers extends React.Component { }).catch((err) => { this.setState({ continueDisabled: false }); if (err.errcode !== 'M_THREEPID_AUTH_FAILED') { - console.error("Unable to verify phone number: " + err); + logger.error("Unable to verify phone number: " + err); Modal.createTrackedDialog('Unable to verify phone number', '', ErrorDialog, { title: _t("Unable to verify phone number."), description: ((err && err.message) ? err.message : _t("Operation failed")), diff --git a/src/components/views/settings/discovery/EmailAddresses.tsx b/src/components/views/settings/discovery/EmailAddresses.tsx index a1375a0f68..48ccc13d72 100644 --- a/src/components/views/settings/discovery/EmailAddresses.tsx +++ b/src/components/views/settings/discovery/EmailAddresses.tsx @@ -26,6 +26,8 @@ import { IThreepid } from "matrix-js-sdk/src/@types/threepids"; import ErrorDialog from "../../dialogs/ErrorDialog"; import AccessibleButton from "../../elements/AccessibleButton"; +import { logger } from "matrix-js-sdk/src/logger"; + /* TODO: Improve the UX for everything in here. It's very much placeholder, but it gets the job done. The old way of handling @@ -98,7 +100,7 @@ export class EmailAddress extends React.Component { private onUnbanClick = (e) => { MatrixClientPeg.get().unban(this.props.member.roomId, this.props.member.userId).catch((err) => { - console.error("Failed to unban: " + err); + logger.error("Failed to unban: " + err); Modal.createTrackedDialog('Failed to unban', '', ErrorDialog, { title: _t('Error'), description: _t('Failed to unban'), @@ -167,7 +169,7 @@ export default class RolesRoomSettingsTab extends React.Component { } client.sendStateEvent(this.props.roomId, EventType.RoomPowerLevels, plContent).catch(e => { - console.error(e); + logger.error(e); Modal.createTrackedDialog('Power level requirement change failed', '', ErrorDialog, { title: _t('Error changing power level requirement'), @@ -193,7 +195,7 @@ export default class RolesRoomSettingsTab extends React.Component { plContent['users'][powerLevelKey] = value; client.sendStateEvent(this.props.roomId, EventType.RoomPowerLevels, plContent).catch(e => { - console.error(e); + logger.error(e); Modal.createTrackedDialog('Power level change failed', '', ErrorDialog, { title: _t('Error changing power level'), diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index d1c5bc8448..0242ace0a6 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -36,6 +36,8 @@ import CreateRoomDialog from '../../../dialogs/CreateRoomDialog'; import JoinRuleSettings from "../../JoinRuleSettings"; import ErrorDialog from "../../../dialogs/ErrorDialog"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { roomId: string; closeSettingsFn: () => void; @@ -180,7 +182,7 @@ export default class SecurityRoomSettingsTab extends React.Component { - console.error(e); + logger.error(e); this.setState({ encrypted: beforeEncrypted }); }); }, @@ -198,7 +200,7 @@ export default class SecurityRoomSettingsTab extends React.Component { - console.error(e); + logger.error(e); this.setState({ guestAccess: beforeGuestAccess }); }); }; @@ -225,7 +227,7 @@ export default class SecurityRoomSettingsTab extends React.Component { - console.error(e); + logger.error(e); this.setState({ history: beforeHistory }); }); }; diff --git a/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx b/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx index bc54a8155c..f2f4e34d79 100644 --- a/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/AppearanceUserSettingsTab.tsx @@ -41,6 +41,8 @@ import { replaceableComponent } from "../../../../../utils/replaceableComponent" import { compare } from "../../../../../utils/strings"; import LayoutSwitcher from "../../LayoutSwitcher"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { } @@ -225,7 +227,7 @@ export default class AppearanceUserSettingsTab extends React.Component void; } @@ -253,7 +255,7 @@ export default class GeneralUserSettingsTab extends React.Component componentDidMount(): void { PlatformPeg.get().getAppVersion().then((ver) => this.setState({ appVersion: ver })).catch((e) => { - console.error("Error getting vector version: ", e); + logger.error("Error getting vector version: ", e); }); PlatformPeg.get().canSelfUpdate().then((v) => this.setState({ canUpdate: v })).catch((e) => { - console.error("Error getting self updatability: ", e); + logger.error("Error getting self updatability: ", e); }); } diff --git a/src/components/views/settings/tabs/user/MjolnirUserSettingsTab.tsx b/src/components/views/settings/tabs/user/MjolnirUserSettingsTab.tsx index 0653198aa0..a05e2b6ee5 100644 --- a/src/components/views/settings/tabs/user/MjolnirUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/MjolnirUserSettingsTab.tsx @@ -28,6 +28,8 @@ import QuestionDialog from "../../../dialogs/QuestionDialog"; import AccessibleButton from "../../../elements/AccessibleButton"; import Field from "../../../elements/Field"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IState { busy: boolean; newPersonalRule: string; @@ -69,7 +71,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> await list.banEntity(kind, this.state.newPersonalRule, _t("Ignored/Blocked")); this.setState({ newPersonalRule: "" }); // this will also cause the new rule to be rendered } catch (e) { - console.error(e); + logger.error(e); Modal.createTrackedDialog('Failed to add Mjolnir rule', '', ErrorDialog, { title: _t('Error adding ignored user/server'), @@ -90,7 +92,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> await Mjolnir.sharedInstance().subscribeToList(room.roomId); this.setState({ newList: "" }); // this will also cause the new rule to be rendered } catch (e) { - console.error(e); + logger.error(e); Modal.createTrackedDialog('Failed to subscribe to Mjolnir list', '', ErrorDialog, { title: _t('Error subscribing to list'), @@ -107,7 +109,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> const list = Mjolnir.sharedInstance().getPersonalList(); await list.unbanEntity(rule.kind, rule.entity); } catch (e) { - console.error(e); + logger.error(e); Modal.createTrackedDialog('Failed to remove Mjolnir rule', '', ErrorDialog, { title: _t('Error removing ignored user/server'), @@ -124,7 +126,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> await Mjolnir.sharedInstance().unsubscribeFromList(list.roomId); await MatrixClientPeg.get().leave(list.roomId); } catch (e) { - console.error(e); + logger.error(e); Modal.createTrackedDialog('Failed to unsubscribe from Mjolnir list', '', ErrorDialog, { title: _t('Error unsubscribing from list'), diff --git a/src/components/views/spaces/SpaceCreateMenu.tsx b/src/components/views/spaces/SpaceCreateMenu.tsx index 22cbb4db65..5ec44e970b 100644 --- a/src/components/views/spaces/SpaceCreateMenu.tsx +++ b/src/components/views/spaces/SpaceCreateMenu.tsx @@ -39,6 +39,8 @@ import { Action } from "../../../dispatcher/actions"; import { UserTab } from "../dialogs/UserSettingsDialog"; import { Key } from "../../../Keyboard"; +import { logger } from "matrix-js-sdk/src/logger"; + export const createSpace = async ( name: string, isPublic: boolean, @@ -255,7 +257,7 @@ const SpaceCreateMenu = ({ onFinished }) => { onFinished(); } catch (e) { - console.error(e); + logger.error(e); } }; diff --git a/src/components/views/spaces/SpaceSettingsGeneralTab.tsx b/src/components/views/spaces/SpaceSettingsGeneralTab.tsx index 595bdb2448..865df03f66 100644 --- a/src/components/views/spaces/SpaceSettingsGeneralTab.tsx +++ b/src/components/views/spaces/SpaceSettingsGeneralTab.tsx @@ -27,6 +27,8 @@ import { IDialogProps } from "../dialogs/IDialogProps"; import { getTopic } from "../elements/RoomTopic"; import { leaveSpace } from "../../../utils/space"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps extends IDialogProps { matrixClient: MatrixClient; space: Room; @@ -83,7 +85,7 @@ const SpaceSettingsGeneralTab = ({ matrixClient: cli, space, onFinished }: IProp setBusy(false); const failures = results.filter(r => r.status === "rejected"); if (failures.length > 0) { - console.error("Failed to save space settings: ", failures); + logger.error("Failed to save space settings: ", failures); setError(_t("Failed to save space settings.")); } }; diff --git a/src/components/views/toasts/VerificationRequestToast.tsx b/src/components/views/toasts/VerificationRequestToast.tsx index 63e23bfdef..c1f1050bc9 100644 --- a/src/components/views/toasts/VerificationRequestToast.tsx +++ b/src/components/views/toasts/VerificationRequestToast.tsx @@ -31,6 +31,8 @@ import { Action } from "../../../dispatcher/actions"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import VerificationRequestDialog from "../dialogs/VerificationRequestDialog"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IProps { toastKey: string; request: VerificationRequest; @@ -98,7 +100,7 @@ export default class VerificationRequestToast extends React.PureComponent { // back to the default after the call is over - Dave element.setSinkId(audioOutput); } catch (e) { - console.error("Couldn't set requested audio output device: using default", e); + logger.error("Couldn't set requested audio output device: using default", e); logger.warn("Couldn't set requested audio output device: using default", e); } } diff --git a/src/createRoom.ts b/src/createRoom.ts index daf8594e23..fae3d8cdc4 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -46,6 +46,8 @@ import { Action } from "./dispatcher/actions"; import ErrorDialog from "./components/views/dialogs/ErrorDialog"; import Spinner from "./components/views/elements/Spinner"; +import { logger } from "matrix-js-sdk/src/logger"; + // we define a number of interfaces which take their names from the js-sdk /* eslint-disable camelcase */ @@ -278,7 +280,7 @@ export default async function createRoom(opts: IOpts): Promise { action: Action.JoinRoomError, roomId, }); - console.error("Failed to create room " + roomId + " " + err); + logger.error("Failed to create room " + roomId + " " + err); let description = _t("Server may be unavailable, overloaded, or you hit a bug."); if (err.errcode === "M_UNSUPPORTED_ROOM_VERSION") { // Technically not possible with the UI as of April 2019 because there's no @@ -356,7 +358,7 @@ export async function canEncryptToAllUsers(client: MatrixClient, userIds: string Object.keys(userDevices).length > 0, ); } catch (e) { - console.error("Error determining if it's possible to encrypt to all users: ", e); + logger.error("Error determining if it's possible to encrypt to all users: ", e); return false; // assume not } } diff --git a/src/integrations/IntegrationManagerInstance.ts b/src/integrations/IntegrationManagerInstance.ts index c3dcd41ee8..51376ae290 100644 --- a/src/integrations/IntegrationManagerInstance.ts +++ b/src/integrations/IntegrationManagerInstance.ts @@ -24,6 +24,8 @@ import SettingsStore from "../settings/SettingsStore"; import IntegrationManager from "../components/views/settings/IntegrationManager"; import { IntegrationManagers } from "./IntegrationManagers"; +import { logger } from "matrix-js-sdk/src/logger"; + export enum Kind { Account = "account", Config = "config", @@ -94,7 +96,7 @@ export class IntegrationManagerInstance { return; } - console.error(e); + logger.error(e); newProps["connected"] = false; } diff --git a/src/integrations/IntegrationManagers.ts b/src/integrations/IntegrationManagers.ts index a16792b193..4ce3171d73 100644 --- a/src/integrations/IntegrationManagers.ts +++ b/src/integrations/IntegrationManagers.ts @@ -224,7 +224,7 @@ export class IntegrationManagers { const result = await fetch(`https://${domainName}/.well-known/matrix/integrations`); wkConfig = await result.json(); } catch (e) { - console.error(e); + logger.error(e); console.warn("Failed to locate integration manager"); return null; } diff --git a/src/languageHandler.tsx b/src/languageHandler.tsx index ad3e34c3f0..822fe445d3 100644 --- a/src/languageHandler.tsx +++ b/src/languageHandler.tsx @@ -353,7 +353,7 @@ export function setLanguage(preferredLangs: string | string[]) { if (!langToUse) { // Fallback to en_EN if none is found langToUse = 'en'; - console.error("Unable to find an appropriate language"); + logger.error("Unable to find an appropriate language"); } return getLanguageRetry(i18nFolder + availLangs[langToUse].fileName); @@ -521,7 +521,7 @@ function weblateToCounterpart(inTrs: object): object { async function getLanguageRetry(langPath: string, num = 3): Promise { return retry(() => getLanguage(langPath), num, e => { logger.log("Failed to load i18n", langPath); - console.error(e); + logger.error(e); return true; // always retry }); } diff --git a/src/notifications/VectorPushRulesDefinitions.ts b/src/notifications/VectorPushRulesDefinitions.ts index a8c617e786..772a7a62ab 100644 --- a/src/notifications/VectorPushRulesDefinitions.ts +++ b/src/notifications/VectorPushRulesDefinitions.ts @@ -20,6 +20,8 @@ import { PushRuleVectorState, VectorState } from "./PushRuleVectorState"; import { NotificationUtils } from "./NotificationUtils"; import { PushRuleAction, PushRuleKind } from "matrix-js-sdk/src/@types/PushRules"; +import { logger } from "matrix-js-sdk/src/logger"; + type StateToActionsMap = { [state in VectorState]?: PushRuleAction[]; }; @@ -70,7 +72,7 @@ class VectorPushRuleDefinition { } } - console.error(`Cannot translate rule actions into Vector rule state. ` + + logger.error(`Cannot translate rule actions into Vector rule state. ` + `Rule: ${JSON.stringify(rule)}, ` + `Expected: ${JSON.stringify(this.vectorStateToActions)}`); return undefined; diff --git a/src/rageshake/rageshake.ts b/src/rageshake/rageshake.ts index acf77c31c0..f275b15a41 100644 --- a/src/rageshake/rageshake.ts +++ b/src/rageshake/rageshake.ts @@ -162,7 +162,7 @@ export class IndexedDBLogStore { // @ts-ignore "Failed to open log database: " + event.target.error.name ); - console.error(err); + logger.error(err); reject(new Error(err)); }; @@ -245,7 +245,7 @@ export class IndexedDBLogStore { resolve(); }; txn.onerror = (event) => { - console.error( + logger.error( "Failed to flush logs : ", event, ); reject( @@ -384,7 +384,7 @@ export class IndexedDBLogStore { Promise.all(removeLogIds.map((id) => deleteLogs(id))).then(() => { logger.log(`Removed ${removeLogIds.length} old logs.`); }, (err) => { - console.error(err); + logger.error(err); }); } return logs; diff --git a/src/settings/SettingsStore.ts b/src/settings/SettingsStore.ts index d2f5568988..df19438ea0 100644 --- a/src/settings/SettingsStore.ts +++ b/src/settings/SettingsStore.ts @@ -550,7 +550,7 @@ export default class SettingsStore { logger.log(`--- ${handlerName}@${roomId || ''} = ${JSON.stringify(value)}`); } catch (e) { logger.log(`--- ${handler}@${roomId || ''} THREW ERROR: ${e.message}`); - console.error(e); + logger.error(e); } if (roomId) { @@ -559,7 +559,7 @@ export default class SettingsStore { logger.log(`--- ${handlerName}@ = ${JSON.stringify(value)}`); } catch (e) { logger.log(`--- ${handler}@ THREW ERROR: ${e.message}`); - console.error(e); + logger.error(e); } } } @@ -572,7 +572,7 @@ export default class SettingsStore { logger.log(`--- SettingsStore#generic@${roomId || ''} = ${JSON.stringify(value)}`); } catch (e) { logger.log(`--- SettingsStore#generic@${roomId || ''} THREW ERROR: ${e.message}`); - console.error(e); + logger.error(e); } if (roomId) { @@ -581,7 +581,7 @@ export default class SettingsStore { logger.log(`--- SettingsStore#generic@ = ${JSON.stringify(value)}`); } catch (e) { logger.log(`--- SettingsStore#generic@$ THREW ERROR: ${e.message}`); - console.error(e); + logger.error(e); } } @@ -591,7 +591,7 @@ export default class SettingsStore { logger.log(`--- SettingsStore#${level}@${roomId || ''} = ${JSON.stringify(value)}`); } catch (e) { logger.log(`--- SettingsStore#${level}@${roomId || ''} THREW ERROR: ${e.message}`); - console.error(e); + logger.error(e); } if (roomId) { @@ -600,7 +600,7 @@ export default class SettingsStore { logger.log(`--- SettingsStore#${level}@ = ${JSON.stringify(value)}`); } catch (e) { logger.log(`--- SettingsStore#${level}@$ THREW ERROR: ${e.message}`); - console.error(e); + logger.error(e); } } } diff --git a/src/stores/FlairStore.js b/src/stores/FlairStore.js index 155d9beaf4..7de5f9405e 100644 --- a/src/stores/FlairStore.js +++ b/src/stores/FlairStore.js @@ -103,7 +103,7 @@ class FlairStore extends EventEmitter { // Return silently to avoid spamming for non-supporting servers return; } - console.error('Could not get groups for user', userId, err); + logger.error('Could not get groups for user', userId, err); throw err; }).finally(() => { delete this._usersInFlight[userId]; diff --git a/src/stores/GroupStore.js b/src/stores/GroupStore.js index 63972b31fb..0934cd9f90 100644 --- a/src/stores/GroupStore.js +++ b/src/stores/GroupStore.js @@ -20,6 +20,8 @@ import FlairStore from './FlairStore'; import { MatrixClientPeg } from '../MatrixClientPeg'; import dis from '../dispatcher/dispatcher'; +import { logger } from "matrix-js-sdk/src/logger"; + export function parseMembersResponse(response) { return response.chunk.map((apiMember) => groupMemberFromApiObject(apiMember)); } @@ -144,7 +146,7 @@ class GroupStore extends EventEmitter { return; } - console.error(`Failed to get resource ${stateKey} for ${groupId}`, err); + logger.error(`Failed to get resource ${stateKey} for ${groupId}`, err); this.emit('error', err, groupId, stateKey); }).finally(() => { // Indicate finished request, allow for future fetches diff --git a/src/stores/ModalWidgetStore.ts b/src/stores/ModalWidgetStore.ts index 851cff3549..abbf87d827 100644 --- a/src/stores/ModalWidgetStore.ts +++ b/src/stores/ModalWidgetStore.ts @@ -22,6 +22,8 @@ import ModalWidgetDialog from "../components/views/dialogs/ModalWidgetDialog"; import { WidgetMessagingStore } from "./widgets/WidgetMessagingStore"; import { IModalWidgetOpenRequestData, IModalWidgetReturnData, Widget } from "matrix-widget-api"; +import { logger } from "matrix-js-sdk/src/logger"; + interface IState { modal?: IModal; openedFromId?: string; @@ -81,7 +83,7 @@ export class ModalWidgetStore extends AsyncStoreWithClient { const sourceMessaging = WidgetMessagingStore.instance.getMessaging(sourceWidget); if (!sourceMessaging) { - console.error("No source widget messaging for modal widget"); + logger.error("No source widget messaging for modal widget"); return; } sourceMessaging.notifyModalWidgetClose(data); diff --git a/src/stores/RoomViewStore.tsx b/src/stores/RoomViewStore.tsx index 0415044d3a..b949ccabcf 100644 --- a/src/stores/RoomViewStore.tsx +++ b/src/stores/RoomViewStore.tsx @@ -235,7 +235,7 @@ class RoomViewStore extends Store { storeRoomAliasInCache(payload.room_alias, result.room_id); roomId = result.room_id; } catch (err) { - console.error("RVS failed to get room id for alias: ", err); + logger.error("RVS failed to get room id for alias: ", err); dis.dispatch({ action: 'view_room_error', room_id: null, diff --git a/src/stores/SetupEncryptionStore.ts b/src/stores/SetupEncryptionStore.ts index e3d4d42591..eefe98c7a2 100644 --- a/src/stores/SetupEncryptionStore.ts +++ b/src/stores/SetupEncryptionStore.ts @@ -248,7 +248,7 @@ export class SetupEncryptionStore extends EventEmitter { this.phase = Phase.Finished; }, true); } catch (e) { - console.error("Error resetting cross-signing", e); + logger.error("Error resetting cross-signing", e); this.phase = Phase.Intro; } this.emit("update"); diff --git a/src/stores/SpaceStore.ts b/src/stores/SpaceStore.ts index b4a1889d3e..966c4af40f 100644 --- a/src/stores/SpaceStore.ts +++ b/src/stores/SpaceStore.ts @@ -41,6 +41,8 @@ import { reorderLexicographically } from "../utils/stringOrderField"; import { TAG_ORDER } from "../components/views/rooms/RoomList"; import { SettingUpdatedPayload } from "../dispatcher/payloads/SettingUpdatedPayload"; +import { logger } from "matrix-js-sdk/src/logger"; + type SpaceKey = string | symbol; interface IState {} @@ -261,7 +263,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient { viaServers: Array.from(viaMap.get(roomInfo.room_id) || []), })); } catch (e) { - console.error(e); + logger.error(e); } return []; }; diff --git a/src/stores/widgets/StopGapWidget.ts b/src/stores/widgets/StopGapWidget.ts index e00c4c6c0b..1293fe0548 100644 --- a/src/stores/widgets/StopGapWidget.ts +++ b/src/stores/widgets/StopGapWidget.ts @@ -401,7 +401,7 @@ export class StopGapWidget extends EventEmitter { } } catch (e) { // All errors are non-fatal - console.error("Error preparing widget communications: ", e); + logger.error("Error preparing widget communications: ", e); } } @@ -473,7 +473,7 @@ export class StopGapWidget extends EventEmitter { const raw = ev.getEffectiveEvent(); this.messaging.feedEvent(raw, this.eventListenerRoomId).catch(e => { - console.error("Error sending event to widget: ", e); + logger.error("Error sending event to widget: ", e); }); } } diff --git a/src/stores/widgets/StopGapWidgetDriver.ts b/src/stores/widgets/StopGapWidgetDriver.ts index 058a605380..e8f550b92c 100644 --- a/src/stores/widgets/StopGapWidgetDriver.ts +++ b/src/stores/widgets/StopGapWidgetDriver.ts @@ -46,6 +46,8 @@ import { tryTransformPermalinkToLocalHref } from "../../utils/permalinks/Permali import { IEvent, MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Room } from "matrix-js-sdk/src/models/room"; +import { logger } from "matrix-js-sdk/src/logger"; + // TODO: Purge this from the universe function getRememberedCapabilitiesForWidget(widget: Widget): Capability[] { @@ -122,7 +124,7 @@ export class StopGapWidgetDriver extends WidgetDriver { (result.approved || []).forEach(cap => allowedSoFar.add(cap)); rememberApproved = result.remember; } catch (e) { - console.error("Non-fatal error getting capabilities: ", e); + logger.error("Non-fatal error getting capabilities: ", e); } } diff --git a/src/utils/AutoDiscoveryUtils.tsx b/src/utils/AutoDiscoveryUtils.tsx index bad87db2b9..ae804381cf 100644 --- a/src/utils/AutoDiscoveryUtils.tsx +++ b/src/utils/AutoDiscoveryUtils.tsx @@ -20,6 +20,8 @@ import { _t, _td, newTranslatableError } from "../languageHandler"; import { makeType } from "./TypeUtils"; import SdkConfig from '../SdkConfig'; +import { logger } from "matrix-js-sdk/src/logger"; + const LIVELINESS_DISCOVERY_ERRORS: string[] = [ AutoDiscovery.ERROR_INVALID_HOMESERVER, AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER, @@ -198,7 +200,7 @@ export default class AutoDiscoveryUtils { if (!discoveryResult || !discoveryResult["m.homeserver"]) { // This shouldn't happen without major misconfiguration, so we'll log a bit of information // in the log so we can find this bit of codee but otherwise tell teh user "it broke". - console.error("Ended up in a state of not knowing which homeserver to connect to."); + logger.error("Ended up in a state of not knowing which homeserver to connect to."); throw newTranslatableError(_td("Unexpected error resolving homeserver configuration")); } @@ -218,7 +220,7 @@ export default class AutoDiscoveryUtils { if (isResult && isResult.state === AutoDiscovery.SUCCESS) { preferredIdentityUrl = isResult["base_url"]; } else if (isResult && isResult.state !== AutoDiscovery.PROMPT) { - console.error("Error determining preferred identity server URL:", isResult); + logger.error("Error determining preferred identity server URL:", isResult); if (isResult.state === AutoDiscovery.FAIL_ERROR) { if (AutoDiscovery.ALL_ERRORS.indexOf(isResult.error) !== -1) { throw newTranslatableError(isResult.error); @@ -234,7 +236,7 @@ export default class AutoDiscoveryUtils { } if (hsResult.state !== AutoDiscovery.SUCCESS) { - console.error("Error processing homeserver config:", hsResult); + logger.error("Error processing homeserver config:", hsResult); if (!syntaxOnly || !AutoDiscoveryUtils.isLivelinessError(hsResult.error)) { if (AutoDiscovery.ALL_ERRORS.indexOf(hsResult.error) !== -1) { throw newTranslatableError(hsResult.error); @@ -251,7 +253,7 @@ export default class AutoDiscoveryUtils { // It should have been set by now, so check it if (!preferredHomeserverName) { - console.error("Failed to parse homeserver name from homeserver URL"); + logger.error("Failed to parse homeserver name from homeserver URL"); throw newTranslatableError(_td("Unexpected error resolving homeserver configuration")); } diff --git a/src/utils/FontManager.ts b/src/utils/FontManager.ts index b0a017be97..24e5c69e24 100644 --- a/src/utils/FontManager.ts +++ b/src/utils/FontManager.ts @@ -39,7 +39,7 @@ function safariVersionCheck(ua: string): boolean { return colrFontSupported; } } catch (err) { - console.error("Error in Safari COLR version check", err); + logger.error("Error in Safari COLR version check", err); } console.warn("Couldn't determine Safari version to check COLR font support, assuming no."); return false; @@ -96,7 +96,7 @@ async function isColrFontSupported(): Promise { logger.log("Canvas check revealed COLR is supported? " + colrFontSupported); return colrFontSupported; } catch (e) { - console.error("Couldn't load COLR font", e); + logger.error("Couldn't load COLR font", e); return false; } } diff --git a/src/utils/IdentityServerUtils.ts b/src/utils/IdentityServerUtils.ts index 47226a1727..ef432f71df 100644 --- a/src/utils/IdentityServerUtils.ts +++ b/src/utils/IdentityServerUtils.ts @@ -19,6 +19,8 @@ import { SERVICE_TYPES } from 'matrix-js-sdk/src/service-types'; import SdkConfig from '../SdkConfig'; import { MatrixClientPeg } from '../MatrixClientPeg'; +import { logger } from "matrix-js-sdk/src/logger"; + export function getDefaultIdentityServerUrl(): string { return SdkConfig.get()['validated_server_config']['isUrl']; } @@ -36,7 +38,7 @@ export async function doesIdentityServerHaveTerms(fullUrl: string): Promise = (w: Whenable) => void; /** @@ -73,7 +75,7 @@ export abstract class Whenable implements IDestroyable { try { listener.fn(this); } catch (e) { - console.error(`Error calling whenable listener for ${condition}:`, e); + logger.error(`Error calling whenable listener for ${condition}:`, e); } } } diff --git a/src/utils/WidgetUtils.ts b/src/utils/WidgetUtils.ts index ea56f2a563..098f18ab09 100644 --- a/src/utils/WidgetUtils.ts +++ b/src/utils/WidgetUtils.ts @@ -31,6 +31,8 @@ import { objectClone } from "./objects"; import { _t } from "../languageHandler"; import { IApp } from "../stores/WidgetStore"; +import { logger } from "matrix-js-sdk/src/logger"; + // How long we wait for the state event echo to come back from the server // before waitFor[Room/User]Widget rejects its promise const WIDGET_WAIT_TIME = 20000; @@ -92,7 +94,7 @@ export default class WidgetUtils { */ static isScalarUrl(testUrlString: string): boolean { if (!testUrlString) { - console.error('Scalar URL check failed. No URL specified'); + logger.error('Scalar URL check failed. No URL specified'); return false; } @@ -246,7 +248,7 @@ export default class WidgetUtils { try { delete userWidgets[widgetId]; } catch (e) { - console.error(`$widgetId is non-configurable`); + logger.error(`$widgetId is non-configurable`); } const addingWidget = Boolean(widgetUrl); diff --git a/src/utils/exportUtils/HtmlExport.tsx b/src/utils/exportUtils/HtmlExport.tsx index cd440537df..a7486e06cf 100644 --- a/src/utils/exportUtils/HtmlExport.tsx +++ b/src/utils/exportUtils/HtmlExport.tsx @@ -379,7 +379,7 @@ export default class HTMLExporter extends Exporter { } else eventTile = await this.getEventTileMarkup(mxEv, joined); } catch (e) { // TODO: Handle callEvent errors - console.error(e); + logger.error(e); eventTile = await this.getEventTileMarkup( this.createModifiedEvent(textForEvent(mxEv), mxEv, false), joined, diff --git a/src/utils/strings.ts b/src/utils/strings.ts index 6d12c88940..1ca7aee630 100644 --- a/src/utils/strings.ts +++ b/src/utils/strings.ts @@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - /** * Copy plaintext to user's clipboard * It will overwrite user's selection range @@ -21,6 +20,8 @@ limitations under the License. * Tries to use new async clipboard API if available * @param text the plaintext to put in the user's clipboard */ +import { logger } from "matrix-js-sdk/src/logger"; + export async function copyPlaintext(text: string): Promise { try { if (navigator && navigator.clipboard && navigator.clipboard.writeText) { @@ -49,7 +50,7 @@ export async function copyPlaintext(text: string): Promise { return successful; } } catch (e) { - console.error("copyPlaintext failed", e); + logger.error("copyPlaintext failed", e); } return false; } diff --git a/src/widgets/ManagedHybrid.ts b/src/widgets/ManagedHybrid.ts index 2adb11da62..f623becbd8 100644 --- a/src/widgets/ManagedHybrid.ts +++ b/src/widgets/ManagedHybrid.ts @@ -23,6 +23,8 @@ import WidgetEchoStore from "../stores/WidgetEchoStore"; import WidgetStore from "../stores/WidgetStore"; import SdkConfig from "../SdkConfig"; +import { logger } from "matrix-js-sdk/src/logger"; + /* eslint-disable camelcase */ interface IManagedHybridWidgetData { widget_id: string; @@ -52,7 +54,7 @@ export async function addManagedHybridWidget(roomId: string) { // Check for permission if (!WidgetUtils.canUserModifyWidgets(roomId)) { - console.error(`User not allowed to modify widgets in ${roomId}`); + logger.error(`User not allowed to modify widgets in ${roomId}`); return; } @@ -67,7 +69,7 @@ export async function addManagedHybridWidget(roomId: string) { const response = await fetch(`${widgetBuildUrl}?roomId=${roomId}`); widgetData = await response.json(); } catch (e) { - console.error(`Managed hybrid widget builder failed for room ${roomId}`, e); + logger.error(`Managed hybrid widget builder failed for room ${roomId}`, e); return; } if (!widgetData) { @@ -82,7 +84,7 @@ export async function addManagedHybridWidget(roomId: string) { WidgetEchoStore.roomHasPendingWidgets(roomId, []) ); if (existing) { - console.error(`Managed hybrid widget already present in room ${roomId}`); + logger.error(`Managed hybrid widget already present in room ${roomId}`); return; } @@ -90,7 +92,7 @@ export async function addManagedHybridWidget(roomId: string) { try { await WidgetUtils.setRoomWidgetContent(roomId, widgetId, widgetContent); } catch (e) { - console.error(`Unable to add managed hybrid widget in room ${roomId}`, e); + logger.error(`Unable to add managed hybrid widget in room ${roomId}`, e); return; }