From 1f1b011fbe99262a3a9724ca1016a5eaa00ee23e Mon Sep 17 00:00:00 2001 From: nanoblit Date: Fri, 29 Sep 2023 15:41:33 +0200 Subject: [PATCH] #3040 - Apply suggestions from reviews --- example/src/App.tsx | 8 ----- .../formatters/identifyStructFormat.ts | 6 ++-- .../application/formatters/serverFormatter.ts | 19 ++++++------ .../src/application/render/raphaelRender.ts | 2 +- .../src/domain/entities/sgroupForest.ts | 4 +-- .../domain/serializers/ket/ketSerializer.ts | 5 +-- .../domain/serializers/mol/molSerializer.ts | 20 +++++------- .../src/domain/serializers/mol/molfile.ts | 10 +++--- .../src/domain/serializers/smi/smiles.js | 14 +++------ .../services/struct/remoteStructService.ts | 11 +++---- .../src/utilities/KetcherLogger.ts | 31 ++++++++++++------- .../src/utilities/runAsyncAction.ts | 4 +-- .../src/state/common/editorSaga.ts | 2 +- .../components/StructRender/StructRender.tsx | 2 +- .../src/script/editor/tool/apoint.utils.ts | 6 ++-- .../src/script/editor/tool/atom.ts | 4 +-- .../src/script/editor/tool/rgroupatom.ts | 4 +-- .../src/script/editor/tool/rgroupfragment.ts | 6 ++-- .../src/script/editor/tool/select.ts | 6 ++-- .../src/script/editor/tool/sgroup.ts | 7 ++--- .../src/script/editor/tool/text.ts | 4 +-- .../src/script/ui/action/copyAs.js | 4 +-- .../script/ui/action/copyImageToClipboard.js | 6 ++-- .../script/ui/component/cliparea/cliparea.jsx | 8 ++--- .../script/ui/component/view/savebutton.tsx | 16 ++++------ .../src/script/ui/state/editor/index.js | 8 ++--- .../script/ui/state/handleHotkeysOverItem.ts | 16 +++++----- .../src/script/ui/state/hotkeys.ts | 2 +- .../src/script/ui/state/modal/atoms.ts | 4 +-- .../src/script/ui/state/modal/bonds.ts | 4 +-- .../src/script/ui/state/server/index.js | 6 ++-- .../src/script/ui/state/shared.ts | 6 ++-- .../src/script/ui/state/templates/index.ts | 8 ++--- .../src/script/ui/state/templates/init-lib.ts | 8 ++--- .../src/script/ui/storage-ext.js | 18 +++++------ .../src/script/ui/utils/optionsManager.ts | 4 +-- .../src/script/ui/utils/settingsManager.ts | 3 +- .../ContextMenu/hooks/useAtomStereo.ts | 6 ++-- .../ContextMenu/hooks/useBondEdit.ts | 6 ++-- .../components/StructEditor/StructEditor.jsx | 5 +-- .../modal/components/document/Save/Save.jsx | 4 +-- .../components/meta/Settings/Settings.tsx | 4 +-- .../modal/components/process/Miew/Miew.tsx | 7 ++--- 43 files changed, 140 insertions(+), 188 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index f6c1b7e5f1..5642fe156c 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -6,8 +6,6 @@ import { Ketcher, RemoteStructServiceProvider, StructServiceProvider, - KetcherLogger, - LogLevel, } from 'ketcher-core'; import { PolymerToggler } from './PolymerToggler'; @@ -74,12 +72,6 @@ const App = () => { onInit={(ketcher: Ketcher) => { window.ketcher = ketcher; - KetcherLogger.settings = { - enabled: true, - level: LogLevel.LOG, - showTrace: false, - }; - window.parent.postMessage( { eventType: 'init', diff --git a/packages/ketcher-core/src/application/formatters/identifyStructFormat.ts b/packages/ketcher-core/src/application/formatters/identifyStructFormat.ts index 006e2150b4..c44c384dbc 100644 --- a/packages/ketcher-core/src/application/formatters/identifyStructFormat.ts +++ b/packages/ketcher-core/src/application/formatters/identifyStructFormat.ts @@ -27,10 +27,8 @@ export function identifyStructFormat( if (JSON.parse(sanitizedString)) { return SupportedFormat.ket; } - } catch (er) { - KetcherLogger.showExceptionLocation( - 'identifyStructFormat.ts::identifyStructFromat', - ); + } catch (e) { + KetcherLogger.error('identifyStructFormat.ts::identifyStructFromat', e); } // eslint-disable-line const isRXN = sanitizedString.includes('$RXN'); diff --git a/packages/ketcher-core/src/application/formatters/serverFormatter.ts b/packages/ketcher-core/src/application/formatters/serverFormatter.ts index 6f395b892c..5c24f05d9b 100644 --- a/packages/ketcher-core/src/application/formatters/serverFormatter.ts +++ b/packages/ketcher-core/src/application/formatters/serverFormatter.ts @@ -71,16 +71,14 @@ export class ServerFormatter implements StructFormatter { ); return convertResult.struct; - } catch (error: any) { + } catch (e: any) { let message; - if (error.message === 'Server is not compatible') { + if (e.message === 'Server is not compatible') { message = `${formatProperties.name} is not supported.`; } else { - message = `Convert error!\n${error.message || error}`; + message = `Convert error!\n${e.message || e}`; } - KetcherLogger.showExceptionLocation( - 'serverFormatter.ts::getStructureFromStructAsync', - ); + KetcherLogger.error('serverFormatter.ts::getStructureFromStructAsync', e); throw new Error(message); } } @@ -111,12 +109,13 @@ export class ServerFormatter implements StructFormatter { parsedStruct.rescale(); } return parsedStruct; - } catch (error: any) { - if (error.message !== 'Server is not compatible') { - KetcherLogger.showExceptionLocation( + } catch (e: any) { + if (e.message !== 'Server is not compatible') { + KetcherLogger.error( 'serverFormatter.ts::getStructureFromStringAsync', + e, ); - throw Error(`Convert error!\n${error.message || error}`); + throw Error(`Convert error!\n${e.message || e}`); } const formatError = diff --git a/packages/ketcher-core/src/application/render/raphaelRender.ts b/packages/ketcher-core/src/application/render/raphaelRender.ts index 04d78b789c..f18845db4a 100644 --- a/packages/ketcher-core/src/application/render/raphaelRender.ts +++ b/packages/ketcher-core/src/application/render/raphaelRender.ts @@ -65,7 +65,7 @@ export class Render { return this.options; } } catch (e) { - KetcherLogger.showExceptionLocation('raphaelRenderer.ts::updateOptions'); + KetcherLogger.error('raphaelRenderer.ts::updateOptions', e); console.log('Not a valid settings object'); } return false; diff --git a/packages/ketcher-core/src/domain/entities/sgroupForest.ts b/packages/ketcher-core/src/domain/entities/sgroupForest.ts index 3e7b797836..7e90ae23f1 100644 --- a/packages/ketcher-core/src/domain/entities/sgroupForest.ts +++ b/packages/ketcher-core/src/domain/entities/sgroupForest.ts @@ -148,9 +148,7 @@ export class SGroupForest { assert(this.parent.has(id), 'sgid is not in the forest'); assert(this.children.has(id), 'sgid is not in the forest'); } catch (e) { - KetcherLogger.showExceptionLocation( - 'sgroupForest.ts::SGroupForest::remove', - ); + KetcherLogger.error('sgroupForest.ts::SGroupForest::remove', e); console.info('error: sgid is not in the forest'); } diff --git a/packages/ketcher-core/src/domain/serializers/ket/ketSerializer.ts b/packages/ketcher-core/src/domain/serializers/ket/ketSerializer.ts index 1ee7a941cf..32e8ee4154 100644 --- a/packages/ketcher-core/src/domain/serializers/ket/ketSerializer.ts +++ b/packages/ketcher-core/src/domain/serializers/ket/ketSerializer.ts @@ -194,9 +194,10 @@ export class KetSerializer implements Serializer { let parsedFileContent: IKetMacromoleculesContent; try { parsedFileContent = JSON.parse(fileContent); - } catch (error) { - KetcherLogger.showExceptionLocation( + } catch (e) { + KetcherLogger.error( 'ketSerializer.ts::KetSerializer::parseAndValidateMacromolecules', + e, ); editor.events.error.dispatch('Error during file parsing'); return { error: true }; diff --git a/packages/ketcher-core/src/domain/serializers/mol/molSerializer.ts b/packages/ketcher-core/src/domain/serializers/mol/molSerializer.ts index 9d5b671128..e76e77d4d8 100644 --- a/packages/ketcher-core/src/domain/serializers/mol/molSerializer.ts +++ b/packages/ketcher-core/src/domain/serializers/mol/molSerializer.ts @@ -47,10 +47,8 @@ export class MolSerializer implements Serializer { try { return molfile.parseCTFile(parseCTFileParams); - } catch (ex) { - KetcherLogger.showExceptionLocation( - 'molSerializer::MolSerializer::deserialize', - ); + } catch (e) { + KetcherLogger.error('molSerializer::MolSerializer::deserialize', e); if (this.options.badHeaderRecover) { try { // check whether there's an extra empty line on top @@ -59,10 +57,8 @@ export class MolSerializer implements Serializer { ...parseCTFileParams, molfileLines: lines.slice(1), }); - } catch (ex1) { - KetcherLogger.showExceptionLocation( - 'molSerializer::MolSerializer::deserialize', - ); + } catch (e1) { + KetcherLogger.error('molSerializer::MolSerializer::deserialize', e1); } try { // check for a missing first line @@ -71,13 +67,11 @@ export class MolSerializer implements Serializer { ...parseCTFileParams, molfileLines: [''].concat(lines), }); - } catch (ex2) { - KetcherLogger.showExceptionLocation( - 'molSerializer::MolSerializer::deserialize', - ); + } catch (e2) { + KetcherLogger.error('molSerializer::MolSerializer::deserialize', e2); } } - throw ex; + throw e; } } diff --git a/packages/ketcher-core/src/domain/serializers/mol/molfile.ts b/packages/ketcher-core/src/domain/serializers/mol/molfile.ts index b41f308751..40d2347222 100644 --- a/packages/ketcher-core/src/domain/serializers/mol/molfile.ts +++ b/packages/ketcher-core/src/domain/serializers/mol/molfile.ts @@ -89,12 +89,10 @@ export class Molfile { try { common.prepareForSaving[sgroup.type](sgroup, mol); - } catch (ex: any) { - KetcherLogger.showExceptionLocation( - 'molfile.ts::Molfile::prepareSGroups', - ); - if (!skipErrors || typeof ex.id !== 'number') { - throw new Error(`Error: ${ex.message}`); + } catch (e: any) { + KetcherLogger.error('molfile.ts::Molfile::prepareSGroups', e); + if (!skipErrors || typeof e.id !== 'number') { + throw new Error(`Error: ${e.message}`); } errorIgnore = true; } diff --git a/packages/ketcher-core/src/domain/serializers/smi/smiles.js b/packages/ketcher-core/src/domain/serializers/smi/smiles.js index 465878e19c..f9ff4ed49e 100644 --- a/packages/ketcher-core/src/domain/serializers/smi/smiles.js +++ b/packages/ketcher-core/src/domain/serializers/smi/smiles.js @@ -71,11 +71,9 @@ Smiles.prototype.saveMolecule = function (struct, ignoreErrors) { if (sg.type === 'MUL') { try { SGroup.prepareMulForSaving(sg, struct); - } catch (ex) { - KetcherLogger.showExceptionLocation( - 'smiles.js::Smiles.prototype.saveMolecule', - ); - throw Error('Bad s-group (' + ex.message + ')'); + } catch (error) { + KetcherLogger.error('smiles.js::Smiles.prototype.saveMolecule', error); + throw Error('Bad s-group (' + error.message + ')'); } } // 'SMILES data format doesn\'t support s-groups' @@ -250,10 +248,8 @@ Smiles.prototype.saveMolecule = function (struct, ignoreErrors) { this.atoms[atomIdx].chirality = 1; } else this.atoms[atomIdx].chirality = 2; }); - } catch (ex) { - KetcherLogger.showExceptionLocation( - 'smiles.js::Smiles.prototype.saveMolecule', - ); + } catch (e) { + KetcherLogger.error('smiles.js::Smiles.prototype.saveMolecule', e); // TODO: add error handler call } diff --git a/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts b/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts index 07d75a534d..078431c137 100644 --- a/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts +++ b/packages/ketcher-core/src/infrastructure/services/struct/remoteStructService.ts @@ -51,11 +51,9 @@ function pollDeferred(process, complete, timeGap, startTimeGap) { try { if (complete(val)) resolve(val); else setTimeout(iterate, timeGap); - } catch (e) { - KetcherLogger.showExceptionLocation( - 'remoteStructService.ts::pollDeferred', - ); - reject(e); + } catch (error) { + KetcherLogger.error('remoteStructService.ts::pollDeferred', error); + reject(error); } }, (err) => reject(err), @@ -172,8 +170,9 @@ export class RemoteStructService implements StructService { imagoVersions = response.imago_versions; isAvailable = true; } catch (e) { - KetcherLogger.showExceptionLocation( + KetcherLogger.error( 'remoteStructService.ts::RemoteStructService::info', + e, ); indigoVersion = ''; imagoVersions = []; diff --git a/packages/ketcher-core/src/utilities/KetcherLogger.ts b/packages/ketcher-core/src/utilities/KetcherLogger.ts index d992c074da..3a79796b05 100644 --- a/packages/ketcher-core/src/utilities/KetcherLogger.ts +++ b/packages/ketcher-core/src/utilities/KetcherLogger.ts @@ -1,7 +1,8 @@ export enum LogLevel { ERROR = 0, WARN = 1, - LOG = 2, + INFO = 2, + LOG = 3, } export interface LogSettings { @@ -27,7 +28,7 @@ export class KetcherLogger { } } - static log(message: unknown): void { + static log(...messages: unknown[]): void { if (!this.isMinimumLogLevel(LogLevel.LOG)) { return; } @@ -35,34 +36,40 @@ export class KetcherLogger { const { showTrace } = this.settings; if (showTrace) { - window.console.trace(message); + window.console.trace(messages); } else { - window.console.log(message); + window.console.log(messages); } } - static warn(warning: unknown): void { - if (!this.isMinimumLogLevel(LogLevel.WARN)) { + static info(...messages: unknown[]): void { + if (!this.isMinimumLogLevel(LogLevel.INFO)) { return; } - window.console.warn(warning); + const { showTrace } = this.settings; + + if (showTrace) { + window.console.trace(messages); + } else { + window.console.info(messages); + } } - static error(error: unknown): void { - if (!this.isMinimumLogLevel(LogLevel.ERROR)) { + static warn(...warnings: unknown[]): void { + if (!this.isMinimumLogLevel(LogLevel.WARN)) { return; } - window.console.error(error); + window.console.warn(warnings); } - static showExceptionLocation(errorLocation: string): void { + static error(...errors: unknown[]): void { if (!this.isMinimumLogLevel(LogLevel.ERROR)) { return; } - window.console.error(`An exception occured in: ${errorLocation}`); + window.console.error(errors); } private static isMinimumLogLevel(minimumLevel: LogLevel): boolean { diff --git a/packages/ketcher-core/src/utilities/runAsyncAction.ts b/packages/ketcher-core/src/utilities/runAsyncAction.ts index 0c9a574e9c..b83420f368 100644 --- a/packages/ketcher-core/src/utilities/runAsyncAction.ts +++ b/packages/ketcher-core/src/utilities/runAsyncAction.ts @@ -32,8 +32,8 @@ export const runAsyncAction = async ( const res = await action(); eventEmitter.emit(KetcherAsyncEvents.SUCCESS); return res; - } catch { - KetcherLogger.showExceptionLocation('runAsyncAction.ts::runAsyncAction'); + } catch (e) { + KetcherLogger.error('runAsyncAction.ts::runAsyncAction', e); eventEmitter.emit(KetcherAsyncEvents.FAILURE); return undefined; } diff --git a/packages/ketcher-polymer-editor-react/src/state/common/editorSaga.ts b/packages/ketcher-polymer-editor-react/src/state/common/editorSaga.ts index d62b312c92..0573e4fba0 100644 --- a/packages/ketcher-polymer-editor-react/src/state/common/editorSaga.ts +++ b/packages/ketcher-polymer-editor-react/src/state/common/editorSaga.ts @@ -31,7 +31,7 @@ function* fetchData() { yield call(fetchDataCall); yield put(initSuccess(editorSlice)); } catch (e) { - KetcherLogger.showExceptionLocation('editorSaga.ts::fetchData'); + KetcherLogger.error('editorSaga.ts::fetchData', e); yield put(initFailure(editorSlice)); } } diff --git a/packages/ketcher-react/src/components/StructRender/StructRender.tsx b/packages/ketcher-react/src/components/StructRender/StructRender.tsx index d8ebac60a1..87517c3363 100644 --- a/packages/ketcher-react/src/components/StructRender/StructRender.tsx +++ b/packages/ketcher-react/src/components/StructRender/StructRender.tsx @@ -32,7 +32,7 @@ const normalizeStruct = (molV2000StringOrStruct: string | Struct) => { try { return new MolSerializer().deserialize(molV2000StringOrStruct); } catch (e) { - KetcherLogger.showExceptionLocation('StructRenderer.tsx::normalizeStruct'); + KetcherLogger.error('StructRenderer.tsx::normalizeStruct', e); throw Error('Could not parse Struct'); } }; diff --git a/packages/ketcher-react/src/script/editor/tool/apoint.utils.ts b/packages/ketcher-react/src/script/editor/tool/apoint.utils.ts index bd9200f4ed..84bfd4ead8 100644 --- a/packages/ketcher-react/src/script/editor/tool/apoint.utils.ts +++ b/packages/ketcher-react/src/script/editor/tool/apoint.utils.ts @@ -36,10 +36,8 @@ export async function editRGroupAttachmentPoint( ); editor.update(action); } - } catch (_error) { - KetcherLogger.showExceptionLocation( - 'apoint.utils.ts::editRGroupAttachmentPoint', - ); + } catch (e) { + KetcherLogger.error('apoint.utils.ts::editRGroupAttachmentPoint', e); // close modal without any operations } } diff --git a/packages/ketcher-react/src/script/editor/tool/atom.ts b/packages/ketcher-react/src/script/editor/tool/atom.ts index a8710aa455..a19a69ce6e 100644 --- a/packages/ketcher-react/src/script/editor/tool/atom.ts +++ b/packages/ketcher-react/src/script/editor/tool/atom.ts @@ -309,8 +309,8 @@ export function atomLongtapEvent(tool, render) { : fromAtomAddition(render.ctab, dragCtx.xy0, newatom); editor.update(action); }) - .catch(() => { - KetcherLogger.showExceptionLocation('atom.ts::atomLongtapEvent'); + .catch((e) => { + KetcherLogger.error('atom.ts::atomLongtapEvent', e); }); // w/o changes }, 750); diff --git a/packages/ketcher-react/src/script/editor/tool/rgroupatom.ts b/packages/ketcher-react/src/script/editor/tool/rgroupatom.ts index 40ad2a7b26..b021e5a5bb 100644 --- a/packages/ketcher-react/src/script/editor/tool/rgroupatom.ts +++ b/packages/ketcher-react/src/script/editor/tool/rgroupatom.ts @@ -133,8 +133,8 @@ function propsDialog(editor, id, pos) { editor.update(fromAtomsAttrs(editor.render.ctab, id, elem, false)); } }) - .catch(() => { - KetcherLogger.showExceptionLocation('rgroupatom.ts:propsDialog'); + .catch((e) => { + KetcherLogger.error('rgroupatom.ts:propsDialog', e); }); // w/o changes } diff --git a/packages/ketcher-react/src/script/editor/tool/rgroupfragment.ts b/packages/ketcher-react/src/script/editor/tool/rgroupfragment.ts index a596e959f5..a14bc01581 100644 --- a/packages/ketcher-react/src/script/editor/tool/rgroupfragment.ts +++ b/packages/ketcher-react/src/script/editor/tool/rgroupfragment.ts @@ -141,10 +141,8 @@ class RGroupFragmentTool implements Tool { editor.update(action); }) - .catch(() => { - KetcherLogger.showExceptionLocation( - 'rgroupfragment.ts::RGroupFragmentTool::click', - ); + .catch((e) => { + KetcherLogger.error('rgroupfragment.ts::RGroupFragmentTool::click', e); }); // w/o changes return true; diff --git a/packages/ketcher-react/src/script/editor/tool/select.ts b/packages/ketcher-react/src/script/editor/tool/select.ts index 25cdb9339c..11b6b952c6 100644 --- a/packages/ketcher-react/src/script/editor/tool/select.ts +++ b/packages/ketcher-react/src/script/editor/tool/select.ts @@ -467,10 +467,8 @@ class SelectTool implements Tool { editor.update(fromTextUpdating(struct, ci.id, content)); } }) - .catch(() => { - KetcherLogger.showExceptionLocation( - 'select.ts::SelectTool::dblclick', - ); + .catch((e) => { + KetcherLogger.error('select.ts::SelectTool::dblclick', e); }); } return true; diff --git a/packages/ketcher-react/src/script/editor/tool/sgroup.ts b/packages/ketcher-react/src/script/editor/tool/sgroup.ts index dcc159d5d7..5207c32824 100644 --- a/packages/ketcher-react/src/script/editor/tool/sgroup.ts +++ b/packages/ketcher-react/src/script/editor/tool/sgroup.ts @@ -538,11 +538,8 @@ class SGroupTool implements Tool { editor.selection(null); } }) - .catch((error) => { - KetcherLogger.showExceptionLocation( - 'sgroup.ts::SGroupTool::sgroupDialog', - ); - console.error(error); + .catch((e) => { + KetcherLogger.error('sgroup.ts::SGroupTool::sgroupDialog', e); }); } } diff --git a/packages/ketcher-react/src/script/editor/tool/text.ts b/packages/ketcher-react/src/script/editor/tool/text.ts index aed2f8c8ca..12c4618558 100644 --- a/packages/ketcher-react/src/script/editor/tool/text.ts +++ b/packages/ketcher-react/src/script/editor/tool/text.ts @@ -149,8 +149,8 @@ function propsDialog( editor.update(fromTextUpdating(editor.render.ctab, id!, content)); } }) - .catch(() => { - KetcherLogger.showExceptionLocation('text.ts::propsDialog'); + .catch((e) => { + KetcherLogger.error('text.ts::propsDialog', e); }); } diff --git a/packages/ketcher-react/src/script/ui/action/copyAs.js b/packages/ketcher-react/src/script/ui/action/copyAs.js index dc2cf1047e..705d1507d1 100644 --- a/packages/ketcher-react/src/script/ui/action/copyAs.js +++ b/packages/ketcher-react/src/script/ui/action/copyAs.js @@ -56,8 +56,8 @@ export default function copyAs(type) { } else { navigator.clipboard.writeText(structData); } - } catch { - KetcherLogger.showExceptionLocation('copyAs.js::copyAs'); + } catch (e) { + KetcherLogger.error('copyAs.js::copyAs', e); errorHandler('This feature is not available in your browser'); } } diff --git a/packages/ketcher-react/src/script/ui/action/copyImageToClipboard.js b/packages/ketcher-react/src/script/ui/action/copyImageToClipboard.js index e2c5da9e52..2f7526a170 100644 --- a/packages/ketcher-react/src/script/ui/action/copyImageToClipboard.js +++ b/packages/ketcher-react/src/script/ui/action/copyImageToClipboard.js @@ -41,10 +41,8 @@ async function copyImageToClipboard() { }); const item = new ClipboardItem({ [image.type]: image }); // eslint-disable-line no-undef await navigator.clipboard.write([item]); - } catch { - KetcherLogger.showExceptionLocation( - 'copyImageToClipboard.js::copyImageToClipboard', - ); + } catch (e) { + KetcherLogger.error('copyImageToClipboard.js::copyImageToClipboard', e); errorHandler('This feature is not available in your browser'); } } diff --git a/packages/ketcher-react/src/script/ui/component/cliparea/cliparea.jsx b/packages/ketcher-react/src/script/ui/component/cliparea/cliparea.jsx index 755a6cdee4..42ca411fee 100644 --- a/packages/ketcher-react/src/script/ui/component/cliparea/cliparea.jsx +++ b/packages/ketcher-react/src/script/ui/component/cliparea/cliparea.jsx @@ -126,8 +126,8 @@ function copy(cb, data) { curFmt = fmt; cb.setData(fmt, data[fmt]); }); - } catch (ex) { - KetcherLogger.showExceptionLocation('cliparea.jsx::copy'); + } catch (e) { + KetcherLogger.error('cliparea.jsx::copy', e); console.info(`Could not write exact type ${curFmt}`); } } @@ -155,9 +155,9 @@ export function exec(action) { if (enabled) { try { enabled = document.execCommand(action) || window.ClipboardEvent || ieCb; - } catch (ex) { + } catch (e) { // FF < 41 - KetcherLogger.showExceptionLocation('cliparea.jsx::exec'); + KetcherLogger.error('cliparea.jsx::exec', e); enabled = false; } } diff --git a/packages/ketcher-react/src/script/ui/component/view/savebutton.tsx b/packages/ketcher-react/src/script/ui/component/view/savebutton.tsx index 9de1d42482..99be152aba 100644 --- a/packages/ketcher-react/src/script/ui/component/view/savebutton.tsx +++ b/packages/ketcher-react/src/script/ui/component/view/savebutton.tsx @@ -67,11 +67,9 @@ const SaveButton = (props: SaveButtonProps) => { saver(data, filename, type); onSave(); }); - } catch (error) { - KetcherLogger.showExceptionLocation( - 'savebutton.tsx::SaveButton::saveFile', - ); - onError(error); + } catch (e) { + KetcherLogger.error('savebutton.tsx::SaveButton::saveFile', e); + onError(e); } } }; @@ -88,11 +86,9 @@ const SaveButton = (props: SaveButtonProps) => { saveAs(blob, `${filename}.${outputFormat}`); onSave(); }) - .catch((error) => { - KetcherLogger.showExceptionLocation( - 'savebutton.tsx::SaveButton::saveImage', - ); - onError(error); + .catch((e) => { + KetcherLogger.error('savebutton.tsx::SaveButton::saveImage', e); + onError(e); }); } }; diff --git a/packages/ketcher-react/src/script/ui/state/editor/index.js b/packages/ketcher-react/src/script/ui/state/editor/index.js index 038a56e8e4..15716402ac 100644 --- a/packages/ketcher-react/src/script/ui/state/editor/index.js +++ b/packages/ketcher-react/src/script/ui/state/editor/index.js @@ -195,9 +195,7 @@ export default function initEditor(dispatch, getState) { serverOpts, struct, ).catch((e) => { - KetcherLogger.showExceptionLocation( - 'index.js::initEditor::onAromatizeStruct', - ); + KetcherLogger.error('index.js::initEditor::onAromatizeStruct', e); state.editor.errorHandler(e); }); }, @@ -211,9 +209,7 @@ export default function initEditor(dispatch, getState) { serverOpts, struct, ).catch((e) => { - KetcherLogger.showExceptionLocation( - 'index.js::initEditor::onDearomatizeStruct', - ); + KetcherLogger.error('index.js::initEditor::onDearomatizeStruct', e); state.editor.errorHandler(e); }); }, diff --git a/packages/ketcher-react/src/script/ui/state/handleHotkeysOverItem.ts b/packages/ketcher-react/src/script/ui/state/handleHotkeysOverItem.ts index ca917f7189..994cfbb125 100644 --- a/packages/ketcher-react/src/script/ui/state/handleHotkeysOverItem.ts +++ b/packages/ketcher-react/src/script/ui/state/handleHotkeysOverItem.ts @@ -160,9 +160,10 @@ function handleAtomPropsDialog({ editor.update(updatedAtom); }) - .catch(() => { - KetcherLogger.showExceptionLocation( + .catch((e) => { + KetcherLogger.error( 'handleHotkeysOverItem.ts::handleAtomPropsDialog', + e, ); }); } @@ -189,9 +190,10 @@ function handleBondPropsDialog({ editor.update(updatedBond); }) - .catch(() => { - KetcherLogger.showExceptionLocation( + .catch((e) => { + KetcherLogger.error( 'handleHoutkeysOverItem.ts::handleBondPropsDialog', + e, ); }); } @@ -355,10 +357,8 @@ async function handleRGroupAtomTool({ hoveredItemId, editor }: HandlersProps) { fromAtomsAttrs(editor.render.ctab, hoveredItemId, element, false), ); } - } catch (error) { - KetcherLogger.showExceptionLocation( - 'handleHotkeysOverItem.ts::handleRGroupAtomTool', - ); + } catch (e) { + KetcherLogger.error('handleHotkeysOverItem.ts::handleRGroupAtomTool', e); } // w/o changes } diff --git a/packages/ketcher-react/src/script/ui/state/hotkeys.ts b/packages/ketcher-react/src/script/ui/state/hotkeys.ts index 4f2497ac23..c8b3ef39cf 100644 --- a/packages/ketcher-react/src/script/ui/state/hotkeys.ts +++ b/packages/ketcher-react/src/script/ui/state/hotkeys.ts @@ -337,7 +337,7 @@ function clipData(editor) { // res['chemical/x-daylight-smiles'] = smiles.stringify(struct); return res; } catch (e: any) { - KetcherLogger.showExceptionLocation('hotkeys.ts::clipData'); + KetcherLogger.error('hotkeys.ts::clipData', e); errorHandler(e.message); } diff --git a/packages/ketcher-react/src/script/ui/state/modal/atoms.ts b/packages/ketcher-react/src/script/ui/state/modal/atoms.ts index ebdc6241ea..5b55bdabd3 100644 --- a/packages/ketcher-react/src/script/ui/state/modal/atoms.ts +++ b/packages/ketcher-react/src/script/ui/state/modal/atoms.ts @@ -46,8 +46,8 @@ export function updateSelectedAtoms({ }); editor.update(action); }) - .catch(() => { - KetcherLogger.showExceptionLocation('atoms.ts::updateSelectedAtoms'); + .catch((e) => { + KetcherLogger.error('atoms.ts::updateSelectedAtoms', e); }); } } diff --git a/packages/ketcher-react/src/script/ui/state/modal/bonds.ts b/packages/ketcher-react/src/script/ui/state/modal/bonds.ts index f262074bdd..fa4ae835a0 100644 --- a/packages/ketcher-react/src/script/ui/state/modal/bonds.ts +++ b/packages/ketcher-react/src/script/ui/state/modal/bonds.ts @@ -33,8 +33,8 @@ export function updateSelectedBonds({ }); editor.update(action); }) - .catch(() => { - KetcherLogger.showExceptionLocation('bonds.ts::updateSelectedBonds'); + .catch((e) => { + KetcherLogger.error('bonds.ts::updateSelectedBonds', e); }); } } diff --git a/packages/ketcher-react/src/script/ui/state/server/index.js b/packages/ketcher-react/src/script/ui/state/server/index.js index 38298c7b43..6c5bc2e2f7 100644 --- a/packages/ketcher-react/src/script/ui/state/server/index.js +++ b/packages/ketcher-react/src/script/ui/state/server/index.js @@ -94,7 +94,7 @@ export function check(optsTypes) { dispatch(checkErrors(res)); }) .catch((e) => { - KetcherLogger.showExceptionLocation('index.js::check'); + KetcherLogger.error('index.js::check', e); editor.errorHandler(e); }); }; @@ -130,7 +130,7 @@ export function analyse() { }), ) .catch((e) => { - KetcherLogger.showExceptionLocation('index.js::analyse'); + KetcherLogger.error('index.js::analyse', e); editor.errorHandler(e); }); }; @@ -156,7 +156,7 @@ export function serverTransform(method, data, struct) { ); }) .catch((e) => { - KetcherLogger.showExceptionLocation('index.js::serverTransform'); + KetcherLogger.error('index.js::serverTransform', e); state.editor.errorHandler(e); }) .finally(() => { diff --git a/packages/ketcher-react/src/script/ui/state/shared.ts b/packages/ketcher-react/src/script/ui/state/shared.ts index 160e1183f2..f652cb241f 100644 --- a/packages/ketcher-react/src/script/ui/state/shared.ts +++ b/packages/ketcher-react/src/script/ui/state/shared.ts @@ -183,10 +183,10 @@ export function load(struct: Struct, options?) { dispatch(setAnalyzingFile(false)); dispatch({ type: 'MODAL_CLOSE' }); - } catch (err: any) { - KetcherLogger.showExceptionLocation('shared.ts::load'); + } catch (e: any) { + KetcherLogger.error('shared.ts::load', e); dispatch(setAnalyzingFile(false)); - err && errorHandler && errorHandler(err.message); + e && errorHandler && errorHandler(e.message); } finally { emitEventRequestIsFinished(); } diff --git a/packages/ketcher-react/src/script/ui/state/templates/index.ts b/packages/ketcher-react/src/script/ui/state/templates/index.ts index da45e70b34..2f83a39ca7 100644 --- a/packages/ketcher-react/src/script/ui/state/templates/index.ts +++ b/packages/ketcher-react/src/script/ui/state/templates/index.ts @@ -97,8 +97,8 @@ export function editTmpl(tmpl) { () => null, ) .then(() => - openDialog(dispatch, 'templates').catch(() => { - KetcherLogger.showExceptionLocation('index.ts::editTmpl'); + openDialog(dispatch, 'templates').catch((e) => { + KetcherLogger.error('index.ts::editTmpl', e); }), ); }; @@ -136,8 +136,8 @@ export function saveUserTmpl(struct) { dispatch(initLib(lib)); updateLocalStore(lib); }) - .catch(() => { - KetcherLogger.showExceptionLocation('index.ts::saveUserTmpl'); + .catch((e) => { + KetcherLogger.error('index.ts::saveUserTmpl', e); }); }; } diff --git a/packages/ketcher-react/src/script/ui/state/templates/init-lib.ts b/packages/ketcher-react/src/script/ui/state/templates/init-lib.ts index eed26d17f4..32c3beaf5f 100644 --- a/packages/ketcher-react/src/script/ui/state/templates/init-lib.ts +++ b/packages/ketcher-react/src/script/ui/state/templates/init-lib.ts @@ -106,8 +106,8 @@ function userTmpls(): SdfItem[] { struct: ketSerializer.deserialize(tmpl.struct), props: tmpl.props, }; - } catch (ex) { - KetcherLogger.showExceptionLocation('init-lib.ts::userTmpls'); + } catch (e) { + KetcherLogger.error('init-lib.ts::userTmpls', e); return null; } }) @@ -145,8 +145,8 @@ function prefetchRender( }, [] as string[]); const fetch = Promise.all( files.map((fn) => - prefetchStatic(baseUrl + fn).catch(() => { - KetcherLogger.showExceptionLocation('init-lib.ts::prefetchRender'); + prefetchStatic(baseUrl + fn).catch((e) => { + KetcherLogger.error('init-lib.ts::prefetchRender', e); }), ), ); diff --git a/packages/ketcher-react/src/script/ui/storage-ext.js b/packages/ketcher-react/src/script/ui/storage-ext.js index cc6b49544c..a08293231f 100644 --- a/packages/ketcher-react/src/script/ui/storage-ext.js +++ b/packages/ketcher-react/src/script/ui/storage-ext.js @@ -24,10 +24,8 @@ export const storage = { try { const storage = global.localStorage; return storage; - } catch (ex) { - KetcherLogger.showExceptionLocation( - 'storage-ext.js::storage::isAvailable', - ); + } catch (e) { + KetcherLogger.error('storage-ext.js::storage::isAvailable', e); return false; } }, @@ -35,9 +33,9 @@ export const storage = { let item = null; try { item = JSON.parse(localStorage.getItem(key)); - } catch (ex) { - KetcherLogger.showExceptionLocation('storage-ext.js::storage::getItem'); - console.info('LocalStorage:', ex.name); + } catch (e) { + KetcherLogger.error('storage-ext.js::storage::getItem', e); + console.info('LocalStorage:', e.name); } return item; }, @@ -46,9 +44,9 @@ export const storage = { try { localStorage.setItem(key, JSON.stringify(data)); isSet = true; - } catch (ex) { - KetcherLogger.showExceptionLocation('storage-ext.js::storage::setItem'); - console.info('LocalStorage:', ex.name); + } catch (e) { + KetcherLogger.error('storage-ext.js::storage::setItem', e); + console.info('LocalStorage:', e.name); isSet = false; } return isSet; diff --git a/packages/ketcher-react/src/script/ui/utils/optionsManager.ts b/packages/ketcher-react/src/script/ui/utils/optionsManager.ts index d08d345505..2a333ad328 100644 --- a/packages/ketcher-react/src/script/ui/utils/optionsManager.ts +++ b/packages/ketcher-react/src/script/ui/utils/optionsManager.ts @@ -12,9 +12,7 @@ export class OptionsManager { localStorage.getItem(KETCHER_SAVED_OPTIONS_KEY) || '{}', ); } catch (e) { - KetcherLogger.showExceptionLocation( - 'optionsManager.ts::OptionsManager::getOptions', - ); + KetcherLogger.error('optionsManager.ts::OptionsManager::getOptions', e); return {} as SavedOptions; } } diff --git a/packages/ketcher-react/src/script/ui/utils/settingsManager.ts b/packages/ketcher-react/src/script/ui/utils/settingsManager.ts index a052b6888e..5894a7bec7 100644 --- a/packages/ketcher-react/src/script/ui/utils/settingsManager.ts +++ b/packages/ketcher-react/src/script/ui/utils/settingsManager.ts @@ -28,8 +28,9 @@ export class SettingsManager { localStorage.getItem(KETCHER_SAVED_SETTINGS_KEY) || '{}', ); } catch (e) { - KetcherLogger.showExceptionLocation( + KetcherLogger.error( 'settingsManager.ts::SettingsManager::getSettings', + e, ); return {} as SavedSettings; } diff --git a/packages/ketcher-react/src/script/ui/views/components/ContextMenu/hooks/useAtomStereo.ts b/packages/ketcher-react/src/script/ui/views/components/ContextMenu/hooks/useAtomStereo.ts index 289bd3f440..9ad9c490ba 100644 --- a/packages/ketcher-react/src/script/ui/views/components/ContextMenu/hooks/useAtomStereo.ts +++ b/packages/ketcher-react/src/script/ui/views/components/ContextMenu/hooks/useAtomStereo.ts @@ -25,10 +25,8 @@ const useAtomStereo = () => { ); action && editor.update(action); - } catch (error) { - KetcherLogger.showExceptionLocation( - 'useAtomStereo.ts::useAtomStereo::handler', - ); + } catch (e) { + KetcherLogger.error('useAtomStereo.ts::useAtomStereo::handler', e); noOperation(); } }, diff --git a/packages/ketcher-react/src/script/ui/views/components/ContextMenu/hooks/useBondEdit.ts b/packages/ketcher-react/src/script/ui/views/components/ContextMenu/hooks/useBondEdit.ts index 34ade5e6bc..86866bd074 100644 --- a/packages/ketcher-react/src/script/ui/views/components/ContextMenu/hooks/useBondEdit.ts +++ b/packages/ketcher-react/src/script/ui/views/components/ContextMenu/hooks/useBondEdit.ts @@ -19,10 +19,8 @@ const useBondEdit = () => { const bonds = mapBondIdsToBonds(bondIds, molecule); const changeBondPromise = await editor.event.bondEdit.dispatch(bonds); updateSelectedBonds({ bonds: bondIds, changeBondPromise, editor }); - } catch (error) { - KetcherLogger.showExceptionLocation( - 'useBondEdit.ts::useBondEdit::handler', - ); + } catch (e) { + KetcherLogger.error('useBondEdit.ts::useBondEdit::handler', e); noOperation(); } }, diff --git a/packages/ketcher-react/src/script/ui/views/components/StructEditor/StructEditor.jsx b/packages/ketcher-react/src/script/ui/views/components/StructEditor/StructEditor.jsx index 1e6221616b..2881004e74 100644 --- a/packages/ketcher-react/src/script/ui/views/components/StructEditor/StructEditor.jsx +++ b/packages/ketcher-react/src/script/ui/views/components/StructEditor/StructEditor.jsx @@ -120,9 +120,10 @@ class StructEditor extends Component { try { const parsedInfo = JSON.parse(msg.info); el.innerHTML = `Atom Id: ${parsedInfo.atomid}, Bond Id: ${parsedInfo.bondid}`; - } catch { - KetcherLogger.showExceptionLocation( + } catch (e) { + KetcherLogger.error( 'StructEditor.jsx::StructEditor::componentDidMount', + e, ); el.innerHTML = msg.info; } diff --git a/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx b/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx index fbbb969a66..6364e4dcfe 100644 --- a/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx +++ b/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx @@ -174,9 +174,7 @@ class SaveDialog extends Component { }); }) .catch((e) => { - KetcherLogger.showExceptionLocation( - 'Save.jsx::SaveDialog::changeType', - ); + KetcherLogger.error('Save.jsx::SaveDialog::changeType', e); errorHandler(e); this.props.onResetForm(formState); return e; diff --git a/packages/ketcher-react/src/script/ui/views/modal/components/meta/Settings/Settings.tsx b/packages/ketcher-react/src/script/ui/views/modal/components/meta/Settings/Settings.tsx index 3694af1672..d291ab923b 100644 --- a/packages/ketcher-react/src/script/ui/views/modal/components/meta/Settings/Settings.tsx +++ b/packages/ketcher-react/src/script/ui/views/modal/components/meta/Settings/Settings.tsx @@ -330,8 +330,8 @@ const mapDispatchToProps = (dispatch, ownProps) => ({ onOpenFile: (newOpts) => { try { dispatch(updateFormState({ result: JSON.parse(newOpts) })); - } catch (ex) { - KetcherLogger.showExceptionLocation('Settings.tsx::mapDispatchToProps'); + } catch (e) { + KetcherLogger.error('Settings.tsx::mapDispatchToProps', e); console.info('Bad file'); } }, diff --git a/packages/ketcher-react/src/script/ui/views/modal/components/process/Miew/Miew.tsx b/packages/ketcher-react/src/script/ui/views/modal/components/process/Miew/Miew.tsx index 733237f799..d1fa3b0a3f 100644 --- a/packages/ketcher-react/src/script/ui/views/modal/components/process/Miew/Miew.tsx +++ b/packages/ketcher-react/src/script/ui/views/modal/components/process/Miew/Miew.tsx @@ -137,11 +137,8 @@ const MiewDialog = ({ miew.setOptions(miewOpts); setIsIsInitialized(true); }) - .catch((ex) => { - KetcherLogger.showExceptionLocation( - 'Miew.tsx::MiewDialog::onMiewInit', - ); - console.error(ex.message); + .catch((e) => { + KetcherLogger.error('Miew.tsx::MiewDialog::onMiewInit', e); }); }, [miewOpts, server, struct],