diff --git a/src/api/converter.ts b/src/api/converter.ts index b1ba92408..e5a1e1752 100644 --- a/src/api/converter.ts +++ b/src/api/converter.ts @@ -202,7 +202,10 @@ function toValueType(valueType: PrimitiveType): PbValueType { case PrimitiveType.Date: return PbValueType.DATE; default: - throw new YorkieError(Code.Unsupported, `unsupported type: ${valueType}`); + throw new YorkieError( + Code.ErrInvalidType, + `unsupported type: ${valueType}`, + ); } } @@ -216,7 +219,10 @@ function toCounterType(valueType: CounterType): PbValueType { case CounterType.LongCnt: return PbValueType.LONG_CNT; default: - throw new YorkieError(Code.Unsupported, `unsupported type: ${valueType}`); + throw new YorkieError( + Code.ErrInvalidType, + `unsupported type: ${valueType}`, + ); } } @@ -859,7 +865,7 @@ function fromPresenceChange
( }; } - throw new YorkieError(Code.Unsupported, `unsupported type: ${type}`); + throw new YorkieError(Code.ErrInvalidType, `unsupported type: ${type}`); } /** @@ -1476,7 +1482,7 @@ function bytesToSnapshot
(
*/
function bytesToObject(bytes?: Uint8Array): CRDTObject {
if (!bytes) {
- throw new Error('bytes is empty');
+ throw new YorkieError(Code.ErrInvalidArgument, 'bytes is empty');
}
const pbElement = PbJSONElement.fromBinary(bytes);
@@ -1495,7 +1501,7 @@ function objectToBytes(obj: CRDTObject): Uint8Array {
*/
function bytesToArray(bytes?: Uint8Array): CRDTArray {
if (!bytes) {
- throw new Error('bytes is empty');
+ throw new YorkieError(Code.ErrInvalidArgument, 'bytes is empty');
}
const pbElement = PbJSONElement.fromBinary(bytes);
@@ -1514,7 +1520,7 @@ function arrayToBytes(array: CRDTArray): Uint8Array {
*/
function bytesToTree(bytes?: Uint8Array): CRDTTree {
if (!bytes) {
- throw new Error('bytes is empty');
+ throw new YorkieError(Code.ErrInvalidArgument, 'bytes is empty');
}
const pbElement = PbJSONElement.fromBinary(bytes);
diff --git a/src/document/crdt/element_rht.ts b/src/document/crdt/element_rht.ts
index d9d3bdadd..83700a549 100644
--- a/src/document/crdt/element_rht.ts
+++ b/src/document/crdt/element_rht.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import { logger } from '@yorkie-js-sdk/src/util/logger';
import { TimeTicket } from '@yorkie-js-sdk/src/document/time/ticket';
import { CRDTElement } from '@yorkie-js-sdk/src/document/crdt/element';
+import { YorkieError, Code } from '@yorkie-js-sdk/src/util/error';
/**
* `ElementRHTNode` is a node of ElementRHT.
@@ -114,7 +114,10 @@ export class ElementRHT {
*/
public delete(createdAt: TimeTicket, executedAt: TimeTicket): CRDTElement {
if (!this.nodeMapByCreatedAt.has(createdAt.toIDString())) {
- logger.fatal(`fail to find ${createdAt.toIDString()}`);
+ throw new YorkieError(
+ Code.ErrInvalidArgument,
+ `fail to find ${createdAt.toIDString()}`,
+ );
}
const node = this.nodeMapByCreatedAt.get(createdAt.toIDString())!;
@@ -142,8 +145,10 @@ export class ElementRHT {
element.getCreatedAt().toIDString(),
);
if (!node) {
- logger.fatal(`fail to find ${element.getCreatedAt().toIDString()}`);
- return;
+ throw new YorkieError(
+ Code.ErrInvalidArgument,
+ `fail to find ${element.getCreatedAt().toIDString()}`,
+ );
}
const nodeByKey = this.nodeMapByKey.get(node.getStrKey());
diff --git a/src/document/crdt/rga_tree_list.ts b/src/document/crdt/rga_tree_list.ts
index df7bd0854..c4901baf0 100644
--- a/src/document/crdt/rga_tree_list.ts
+++ b/src/document/crdt/rga_tree_list.ts
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import { logger } from '@yorkie-js-sdk/src/util/logger';
import { SplayNode, SplayTree } from '@yorkie-js-sdk/src/util/splay_tree';
import {
InitialTimeTicket,
@@ -22,6 +21,7 @@ import {
} from '@yorkie-js-sdk/src/document/time/ticket';
import { CRDTElement } from '@yorkie-js-sdk/src/document/crdt/element';
import { Primitive } from '@yorkie-js-sdk/src/document/crdt/primitive';
+import { Code, YorkieError } from '@yorkie-js-sdk/src/util/error';
/**
* `RGATreeListNode` is a node of RGATreeList.
@@ -180,7 +180,10 @@ export class RGATreeList {
): RGATreeListNode {
let node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
if (!node) {
- logger.fatal(`cant find the given node: ${createdAt.toIDString()}`);
+ throw new YorkieError(
+ Code.ErrInvalidArgument,
+ `cant find the given node: ${createdAt.toIDString()}`,
+ );
}
while (
@@ -232,12 +235,18 @@ export class RGATreeList {
): void {
const prevNode = this.nodeMapByCreatedAt.get(prevCreatedAt.toIDString());
if (!prevNode) {
- logger.fatal(`cant find the given node: ${prevCreatedAt.toIDString()}`);
+ throw new YorkieError(
+ Code.ErrInvalidArgument,
+ `cant find the given node: ${prevCreatedAt.toIDString()}`,
+ );
}
const node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
if (!node) {
- logger.fatal(`cant find the given node: ${createdAt.toIDString()}`);
+ throw new YorkieError(
+ Code.ErrInvalidArgument,
+ `cant find the given node: ${createdAt.toIDString()}`,
+ );
}
if (
@@ -284,7 +293,8 @@ export class RGATreeList {
element.getCreatedAt().toIDString(),
);
if (!node) {
- logger.fatal(
+ throw new YorkieError(
+ Code.ErrInvalidArgument,
`fail to find the given createdAt: ${element
.getCreatedAt()
.toIDString()}`,
diff --git a/src/document/crdt/rga_tree_split.ts b/src/document/crdt/rga_tree_split.ts
index 0d28d0895..45d8fd34d 100644
--- a/src/document/crdt/rga_tree_split.ts
+++ b/src/document/crdt/rga_tree_split.ts
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import { logger } from '@yorkie-js-sdk/src/util/logger';
import { ActorID } from '@yorkie-js-sdk/src/document/time/actor_id';
import { Comparator } from '@yorkie-js-sdk/src/util/comparator';
import { SplayNode, SplayTree } from '@yorkie-js-sdk/src/util/splay_tree';
@@ -26,6 +25,7 @@ import {
TimeTicketStruct,
} from '@yorkie-js-sdk/src/document/time/ticket';
import { GCChild, GCPair, GCParent } from '@yorkie-js-sdk/src/document/crdt/gc';
+import { Code, YorkieError } from '@yorkie-js-sdk/src/util/error';
export interface ValueChange ['presence'];
@@ -1021,7 +1024,7 @@ export class Document