Skip to content

Commit

Permalink
Remove logger.fatal when used with 'throw new YorkieError
Browse files Browse the repository at this point in the history
There is a problem of code being verbose with duuplicated logging and error throwing. Removing logger will temproarily resolve the issue.
  • Loading branch information
gwbaik9717 committed Aug 6, 2024
1 parent bc21654 commit b6c5213
Show file tree
Hide file tree
Showing 18 changed files with 0 additions and 47 deletions.
2 changes: 0 additions & 2 deletions src/document/crdt/element_rht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -148,7 +147,6 @@ export class ElementRHT {
const ErrorMessage = `fail to find ${element
.getCreatedAt()
.toIDString()}`;
logger.fatal(ErrorMessage);
throw new YorkieError(Code.ErrInvalidArgument, ErrorMessage);
}

Expand Down
4 changes: 0 additions & 4 deletions src/document/crdt/rga_tree_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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!);
Expand Down
3 changes: 0 additions & 3 deletions src/document/crdt/rga_tree_split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,6 @@ export class RGATreeSplit<T extends RGATreeSplitValue> 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!);
Expand Down Expand Up @@ -795,7 +794,6 @@ export class RGATreeSplit<T extends RGATreeSplitValue> 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);
}

Expand Down Expand Up @@ -849,7 +847,6 @@ export class RGATreeSplit<T extends RGATreeSplitValue> implements GCParent {
): RGATreeSplitNode<T> | 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);
}

Expand Down
2 changes: 0 additions & 2 deletions src/document/crdt/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import { logger } from '@yorkie-js-sdk/src/util/logger';
import {
InitialTimeTicket,
TimeTicket,
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion src/document/json/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 0 additions & 10 deletions src/document/json/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ export class Text<A extends Indexable = Indexable> {
): [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);
}

Expand Down Expand Up @@ -158,13 +156,11 @@ export class Text<A extends Indexable = Indexable> {
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);
}

Expand Down Expand Up @@ -209,7 +205,6 @@ export class Text<A extends Indexable = Indexable> {
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);
}

Expand All @@ -223,7 +218,6 @@ export class Text<A extends Indexable = Indexable> {
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);
}

Expand All @@ -241,7 +235,6 @@ export class Text<A extends Indexable = Indexable> {
toTestString(): string {
if (!this.context || !this.text) {
const ErrorMessage = 'Text is not initialized yet';
logger.fatal(ErrorMessage);
throw new YorkieError(Code.ErrNotInitialized, ErrorMessage);
}

Expand All @@ -254,7 +247,6 @@ export class Text<A extends Indexable = Indexable> {
values(): Array<TextValueType<A>> {
if (!this.context || !this.text) {
const ErrorMessage = 'Text is not initialized yet';
logger.fatal(ErrorMessage);
throw new YorkieError(Code.ErrNotInitialized, ErrorMessage);
}

Expand Down Expand Up @@ -291,7 +283,6 @@ export class Text<A extends Indexable = Indexable> {
toString(): string {
if (!this.context || !this.text) {
const ErrorMessage = 'Text is not initialized yet';
logger.fatal(ErrorMessage);
throw new YorkieError(Code.ErrNotInitialized, ErrorMessage);
}

Expand Down Expand Up @@ -334,7 +325,6 @@ export class Text<A extends Indexable = Indexable> {
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);
}

Expand Down
4 changes: 0 additions & 4 deletions src/document/json/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -791,7 +788,6 @@ export class Tree {
): [Array<number>, Array<number>] {
if (!this.context || !this.tree) {
const ErrorMessage = 'Tree is not initialized yet';
logger.fatal(ErrorMessage);
throw new YorkieError(Code.ErrNotInitialized, ErrorMessage);
}

Expand Down
2 changes: 0 additions & 2 deletions src/document/operation/add_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/document/operation/edit_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions src/document/operation/increase_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/document/operation/move_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/document/operation/remove_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions src/document/operation/set_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions src/document/operation/style_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<A>;
Expand Down
2 changes: 0 additions & 2 deletions src/document/operation/tree_edit_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions src/document/operation/tree_style_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/util/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,11 @@ class ObserverProxy<T> implements Observer<T> {

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);
}

Expand Down
1 change: 0 additions & 1 deletion src/util/splay_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ export class SplayTree<V> {
}
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];
Expand Down

0 comments on commit b6c5213

Please sign in to comment.