Skip to content

Commit b88befb

Browse files
fix
1 parent 589b841 commit b88befb

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

index.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class DataEncoder extends CoderConst {
154154
if (!oTools.isUndefined(val)) res = Buffer.concat([res, val]);
155155
return res;
156156
} catch (e) {
157-
throw Error('Decoder error: make');
157+
throw Error('Encoder error: make');
158158
}
159159
}
160160

@@ -182,7 +182,7 @@ class DataEncoder extends CoderConst {
182182
return undefined;
183183

184184
} catch (e) {
185-
throw Error(`Decoder error: custom [${handler.id}]`);
185+
throw Error(`Encoder error: custom [${handler.id}]`);
186186
}
187187
}
188188

@@ -200,7 +200,7 @@ class DataEncoder extends CoderConst {
200200
if (oTools.isArray(val)) return this.arr(val);
201201
if (oTools.isObject(val)) return this.obj(val);
202202

203-
throw Error('Decoder error: unknown type');
203+
throw Error('Encoder error: unknown type');
204204
}
205205

206206
encode(val) {
@@ -215,7 +215,7 @@ class DataEncoder extends CoderConst {
215215
tools.int32UToBuf(int53arr[1])
216216
]));
217217
} catch (e) {
218-
throw Error('Decoder error: date');
218+
throw Error('Encoder error: date');
219219
}
220220
}
221221

@@ -243,15 +243,15 @@ class DataEncoder extends CoderConst {
243243
if (val.length <= 0xffff) return _bin(this.type.BINARY16, tools.int16UToBuf(val.length), val);
244244
return _bin(this.type.BINARY32, tools.int32UToBuf(val.length), val);
245245
} catch (e) {
246-
throw Error('Decoder error: bin');
246+
throw Error('Encoder error: bin');
247247
}
248248
}
249249

250250
binFlags(val) {
251251
try {
252252
return this.make(this.type.BINFLAGS, this.tools.binFlagsToBuf(val));
253253
} catch (e) {
254-
throw Error('Decoder error: binFlags');
254+
throw Error('Encoder error: binFlags');
255255
}
256256
}
257257

@@ -266,7 +266,7 @@ class DataEncoder extends CoderConst {
266266
if (len <= 0xffff) return _obj(this.type.OBJECT16, tools.int16UToBuf(len), rows);
267267
return _obj(this.type.OBJECT32, tools.int32UToBuf(len), rows);
268268
} catch (e) {
269-
throw Error('Decoder error: obj');
269+
throw Error('Encoder error: obj');
270270
}
271271
}
272272

@@ -280,7 +280,7 @@ class DataEncoder extends CoderConst {
280280
if (rows.length <= 0xffff) return _arr(this.type.ARRAY16, tools.int16UToBuf(rows.length), rows);
281281
return _arr(this.type.ARRAY32, tools.int32UToBuf(rows.length), rows);
282282
} catch (e) {
283-
throw Error('Decoder error: arr');
283+
throw Error('Encoder error: arr');
284284
}
285285
}
286286

@@ -293,7 +293,7 @@ class DataEncoder extends CoderConst {
293293
if (!oTools.isString(val) || !val) return false;
294294
return this.make(this.type.CHAR, Buffer.from(val[0], 'ascii'));
295295
} catch (e) {
296-
throw Error('Decoder error: char');
296+
throw Error('Encoder error: char');
297297
}
298298
}
299299

@@ -309,7 +309,7 @@ class DataEncoder extends CoderConst {
309309
if (str.length <= 0xffff) return _make(ascii ? this.type.STRA16 : this.type.STR16, tools.int16UToBuf(str.length), str);
310310
return _make(ascii ? this.type.STRA32 : this.type.STR32, tools.int32UToBuf(str.length), str);
311311
} catch (e) {
312-
throw Error('Decoder error: str');
312+
throw Error('Encoder error: str');
313313
}
314314
}
315315

@@ -341,7 +341,7 @@ class DataEncoder extends CoderConst {
341341
}
342342
return _toBigNum(new BigNumber(val));
343343
} catch (e) {
344-
throw Error('Decoder error: int');
344+
throw Error('Encoder error: int');
345345
}
346346
}
347347
}
@@ -353,7 +353,11 @@ class DataDecoder extends CoderConst {
353353
}
354354

355355
decode(msg) {
356-
return this.decodeWLen(msg)[0];
356+
try {
357+
return this.decodeWLen(msg)[0];
358+
} catch (e) {
359+
throw Error('Decoder error: decode');
360+
}
357361
}
358362

359363
extract(msg, start, end) {

0 commit comments

Comments
 (0)