From b6c5213e3ffedd2b10b4cc9a9752111d7ea69a05 Mon Sep 17 00:00:00 2001 From: Gunwoo Baik Date: Tue, 6 Aug 2024 22:15:32 +0000 Subject: [PATCH] Remove logger.fatal when used with 'throw new YorkieError There is a problem of code being verbose with duuplicated logging and error throwing. Removing logger will temproarily resolve the issue. --- src/document/crdt/element_rht.ts | 2 -- src/document/crdt/rga_tree_list.ts | 4 ---- src/document/crdt/rga_tree_split.ts | 3 --- src/document/crdt/root.ts | 2 -- src/document/json/counter.ts | 1 - src/document/json/text.ts | 10 ---------- src/document/json/tree.ts | 4 ---- src/document/operation/add_operation.ts | 2 -- src/document/operation/edit_operation.ts | 2 -- src/document/operation/increase_operation.ts | 2 -- src/document/operation/move_operation.ts | 2 -- src/document/operation/remove_operation.ts | 2 -- src/document/operation/set_operation.ts | 2 -- src/document/operation/style_operation.ts | 2 -- src/document/operation/tree_edit_operation.ts | 2 -- src/document/operation/tree_style_operation.ts | 2 -- src/util/observable.ts | 2 -- src/util/splay_tree.ts | 1 - 18 files changed, 47 deletions(-) diff --git a/src/document/crdt/element_rht.ts b/src/document/crdt/element_rht.ts index 2c36081b2..6fd9fd943 100644 --- a/src/document/crdt/element_rht.ts +++ b/src/document/crdt/element_rht.ts @@ -116,7 +116,6 @@ export class ElementRHT { public delete(createdAt: TimeTicket, executedAt: TimeTicket): CRDTElement { if (!this.nodeMapByCreatedAt.has(createdAt.toIDString())) { const ErrorMessage = `fail to find ${createdAt.toIDString()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } @@ -148,7 +147,6 @@ export class ElementRHT { const ErrorMessage = `fail to find ${element .getCreatedAt() .toIDString()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } diff --git a/src/document/crdt/rga_tree_list.ts b/src/document/crdt/rga_tree_list.ts index 16146b236..d373fdd66 100644 --- a/src/document/crdt/rga_tree_list.ts +++ b/src/document/crdt/rga_tree_list.ts @@ -182,7 +182,6 @@ export class RGATreeList { let node = this.nodeMapByCreatedAt.get(createdAt.toIDString()); if (!node) { const ErrorMessage = `cant find the given node: ${createdAt.toIDString()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } @@ -236,14 +235,12 @@ export class RGATreeList { const prevNode = this.nodeMapByCreatedAt.get(prevCreatedAt.toIDString()); if (!prevNode) { const ErrorMessage = `cant find the given node: ${prevCreatedAt.toIDString()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } const node = this.nodeMapByCreatedAt.get(createdAt.toIDString()); if (!node) { const ErrorMessage = `cant find the given node: ${createdAt.toIDString()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } @@ -294,7 +291,6 @@ export class RGATreeList { const ErrorMessage = `fail to find the given createdAt: ${element .getCreatedAt() .toIDString()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } this.release(node!); diff --git a/src/document/crdt/rga_tree_split.ts b/src/document/crdt/rga_tree_split.ts index 4c2558f45..4760c41e1 100644 --- a/src/document/crdt/rga_tree_split.ts +++ b/src/document/crdt/rga_tree_split.ts @@ -636,7 +636,6 @@ export class RGATreeSplit implements GCParent { : this.findFloorNode(absoluteID); if (!node) { const ErrorMessage = `the node of the given id should be found: ${absoluteID.toTestString()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } const index = this.treeByIndex.indexOf(node!); @@ -795,7 +794,6 @@ export class RGATreeSplit implements GCParent { let node = this.findFloorNode(id); if (!node) { const ErrorMessage = `the node of the given id should be found: ${id.toTestString()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } @@ -849,7 +847,6 @@ export class RGATreeSplit implements GCParent { ): RGATreeSplitNode | undefined { if (offset > node.getContentLength()) { const ErrorMessage = `offset should be less than or equal to length`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } diff --git a/src/document/crdt/root.ts b/src/document/crdt/root.ts index 2a31907d7..e8944d4cf 100644 --- a/src/document/crdt/root.ts +++ b/src/document/crdt/root.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { logger } from '@yorkie-js-sdk/src/util/logger'; import { InitialTimeTicket, TimeTicket, @@ -136,7 +135,6 @@ export class CRDTRoot { const subPath = pair.parent.subPathOf(createdAt); if (subPath === undefined) { const ErrorMessage = `cant find the given element: ${createdAt.toIDString()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } diff --git a/src/document/json/counter.ts b/src/document/json/counter.ts index 358a49b00..557bb44e4 100644 --- a/src/document/json/counter.ts +++ b/src/document/json/counter.ts @@ -80,7 +80,6 @@ export class Counter { public increase(v: number | Long): Counter { if (!this.context || !this.counter) { const ErrorMessage = 'Counter is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } diff --git a/src/document/json/text.ts b/src/document/json/text.ts index 961e2ca6c..407a229b4 100644 --- a/src/document/json/text.ts +++ b/src/document/json/text.ts @@ -94,13 +94,11 @@ export class Text { ): [number, number] | undefined { if (!this.context || !this.text) { const ErrorMessage = 'Text is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } if (fromIdx > toIdx) { const ErrorMessage = 'from should be less than or equal to to'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } @@ -158,13 +156,11 @@ export class Text { setStyle(fromIdx: number, toIdx: number, attributes: A): boolean { if (!this.context || !this.text) { const ErrorMessage = 'Text is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } if (fromIdx > toIdx) { const ErrorMessage = 'from should be less than or equal to to'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } @@ -209,7 +205,6 @@ export class Text { indexRangeToPosRange(range: [number, number]): TextPosStructRange { if (!this.context || !this.text) { const ErrorMessage = 'Text is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } @@ -223,7 +218,6 @@ export class Text { posRangeToIndexRange(range: TextPosStructRange): [number, number] { if (!this.context || !this.text) { const ErrorMessage = 'Text is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } @@ -241,7 +235,6 @@ export class Text { toTestString(): string { if (!this.context || !this.text) { const ErrorMessage = 'Text is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } @@ -254,7 +247,6 @@ export class Text { values(): Array> { if (!this.context || !this.text) { const ErrorMessage = 'Text is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } @@ -291,7 +283,6 @@ export class Text { toString(): string { if (!this.context || !this.text) { const ErrorMessage = 'Text is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } @@ -334,7 +325,6 @@ export class Text { createRangeForTest(fromIdx: number, toIdx: number): RGATreeSplitPosRange { if (!this.context || !this.text) { const ErrorMessage = 'Text is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } diff --git a/src/document/json/tree.ts b/src/document/json/tree.ts index c6125896e..074e26557 100644 --- a/src/document/json/tree.ts +++ b/src/document/json/tree.ts @@ -740,7 +740,6 @@ export class Tree { ): TreePosStructRange { if (!this.context || !this.tree) { const ErrorMessage = 'Tree is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } @@ -758,7 +757,6 @@ export class Tree { indexRangeToPosRange(range: [number, number]): TreePosStructRange { if (!this.context || !this.tree) { const ErrorMessage = 'Tree is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } @@ -771,7 +769,6 @@ export class Tree { posRangeToIndexRange(range: TreePosStructRange): [number, number] { if (!this.context || !this.tree) { const ErrorMessage = 'Tree is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } @@ -791,7 +788,6 @@ export class Tree { ): [Array, Array] { if (!this.context || !this.tree) { const ErrorMessage = 'Tree is not initialized yet'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrNotInitialized, ErrorMessage); } diff --git a/src/document/operation/add_operation.ts b/src/document/operation/add_operation.ts index 3526b7e3a..a1a09dfa1 100644 --- a/src/document/operation/add_operation.ts +++ b/src/document/operation/add_operation.ts @@ -62,12 +62,10 @@ export class AddOperation extends Operation { const parentObject = root.findByCreatedAt(this.getParentCreatedAt()); if (!parentObject) { const ErrorMessage = `fail to find ${this.getParentCreatedAt()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } if (!(parentObject instanceof CRDTArray)) { const ErrorMessage = `fail to execute, only array can execute add`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } const array = parentObject as CRDTArray; diff --git a/src/document/operation/edit_operation.ts b/src/document/operation/edit_operation.ts index 491d6314d..f604b2ea0 100644 --- a/src/document/operation/edit_operation.ts +++ b/src/document/operation/edit_operation.ts @@ -85,12 +85,10 @@ export class EditOperation extends Operation { const parentObject = root.findByCreatedAt(this.getParentCreatedAt()); if (!parentObject) { const ErrorMessage = `fail to find ${this.getParentCreatedAt()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } if (!(parentObject instanceof CRDTText)) { const ErrorMessage = `fail to execute, only Text can execute edit`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } diff --git a/src/document/operation/increase_operation.ts b/src/document/operation/increase_operation.ts index 7dab3bcb0..99c29aba7 100644 --- a/src/document/operation/increase_operation.ts +++ b/src/document/operation/increase_operation.ts @@ -64,12 +64,10 @@ export class IncreaseOperation extends Operation { const parentObject = root.findByCreatedAt(this.getParentCreatedAt()); if (!parentObject) { const ErrorMessage = `fail to find ${this.getParentCreatedAt()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } if (!(parentObject instanceof CRDTCounter)) { const ErrorMessage = `fail to execute, only Counter can execute increase`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } const counter = parentObject as CRDTCounter; diff --git a/src/document/operation/move_operation.ts b/src/document/operation/move_operation.ts index 2b8573136..3a41939a2 100644 --- a/src/document/operation/move_operation.ts +++ b/src/document/operation/move_operation.ts @@ -66,12 +66,10 @@ export class MoveOperation extends Operation { const parentObject = root.findByCreatedAt(this.getParentCreatedAt()); if (!parentObject) { const ErrorMessage = `fail to find ${this.getParentCreatedAt()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } if (!(parentObject instanceof CRDTArray)) { const ErrorMessage = `fail to execute, only array can execute move`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } const array = parentObject as CRDTArray; diff --git a/src/document/operation/remove_operation.ts b/src/document/operation/remove_operation.ts index 5b92043c3..822bb798f 100644 --- a/src/document/operation/remove_operation.ts +++ b/src/document/operation/remove_operation.ts @@ -70,12 +70,10 @@ export class RemoveOperation extends Operation { ) as CRDTContainer; if (!container) { const ErrorMessage = `fail to find ${this.getParentCreatedAt()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } if (!(container instanceof CRDTContainer)) { const ErrorMessage = `only object and array can execute remove: ${container}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } diff --git a/src/document/operation/set_operation.ts b/src/document/operation/set_operation.ts index 2c32769ee..5522d6790 100644 --- a/src/document/operation/set_operation.ts +++ b/src/document/operation/set_operation.ts @@ -68,12 +68,10 @@ export class SetOperation extends Operation { const obj = root.findByCreatedAt(this.getParentCreatedAt()) as CRDTObject; if (!obj) { const ErrorMessage = `fail to find ${this.getParentCreatedAt()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } if (!(obj instanceof CRDTObject)) { const ErrorMessage = `fail to execute, only object can execute set`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } diff --git a/src/document/operation/style_operation.ts b/src/document/operation/style_operation.ts index ab5945a38..dd2300b35 100644 --- a/src/document/operation/style_operation.ts +++ b/src/document/operation/style_operation.ts @@ -79,12 +79,10 @@ export class StyleOperation extends Operation { const parentObject = root.findByCreatedAt(this.getParentCreatedAt()); if (!parentObject) { const ErrorMessage = `fail to find ${this.getParentCreatedAt()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } if (!(parentObject instanceof CRDTText)) { const ErrorMessage = `fail to execute, only Text can execute edit`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } const text = parentObject as CRDTText; diff --git a/src/document/operation/tree_edit_operation.ts b/src/document/operation/tree_edit_operation.ts index 662566586..6f9d39de0 100644 --- a/src/document/operation/tree_edit_operation.ts +++ b/src/document/operation/tree_edit_operation.ts @@ -87,12 +87,10 @@ export class TreeEditOperation extends Operation { const parentObject = root.findByCreatedAt(this.getParentCreatedAt()); if (!parentObject) { const ErrorMessage = `fail to find ${this.getParentCreatedAt()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } if (!(parentObject instanceof CRDTTree)) { const ErrorMessage = `fail to execute, only Tree can execute edit`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } const editedAt = this.getExecutedAt(); diff --git a/src/document/operation/tree_style_operation.ts b/src/document/operation/tree_style_operation.ts index 65b0e68d9..a03473329 100644 --- a/src/document/operation/tree_style_operation.ts +++ b/src/document/operation/tree_style_operation.ts @@ -109,12 +109,10 @@ export class TreeStyleOperation extends Operation { const parentObject = root.findByCreatedAt(this.getParentCreatedAt()); if (!parentObject) { const ErrorMessage = `fail to find ${this.getParentCreatedAt()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } if (!(parentObject instanceof CRDTTree)) { const ErrorMessage = `fail to execute, only Tree can execute edit`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } const tree = parentObject as CRDTTree; diff --git a/src/util/observable.ts b/src/util/observable.ts index f20150dea..29a27bea4 100644 --- a/src/util/observable.ts +++ b/src/util/observable.ts @@ -108,13 +108,11 @@ class ObserverProxy implements Observer { if (!nextOrObserver) { const ErrorMessage = 'missing observer'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } if (this.finalized) { const ErrorMessage = 'observable is finalized due to previous error'; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrRefused, ErrorMessage); } diff --git a/src/util/splay_tree.ts b/src/util/splay_tree.ts index bac9c38e6..c69889c57 100644 --- a/src/util/splay_tree.ts +++ b/src/util/splay_tree.ts @@ -208,7 +208,6 @@ export class SplayTree { } if (pos > node.getLength()) { const ErrorMessage = `out of index range: pos: ${pos} > node.length: ${node.getLength()}`; - logger.fatal(ErrorMessage); throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage); } return [node, pos];