Skip to content

Commit ecef04a

Browse files
committed
refactor: use TypeError for type-related errors
1 parent 5bdb291 commit ecef04a

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/lib/plist/binary-plist-parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ class BinaryPlistParser {
267267
if (objInfo === 0x0f) {
268268
const intType = this._buffer.readUInt8(startOffset) & 0xf0;
269269
if (intType !== BPLIST_TYPE.INT) {
270-
throw new Error(
270+
throw new TypeError(
271271
`Expected integer type for length at offset ${startOffset}`,
272272
);
273273
}
@@ -341,7 +341,7 @@ class BinaryPlistParser {
341341
return this._createTempDict(objLength, startOffset);
342342

343343
default:
344-
throw new Error(
344+
throw new TypeError(
345345
`Unsupported binary plist object type: ${objType.toString(16)}`,
346346
);
347347
}
@@ -462,7 +462,7 @@ class BinaryPlistParser {
462462
const value = this._objectTable[valueRef];
463463

464464
if (typeof key !== 'string') {
465-
throw new Error(`Dictionary key must be a string, got ${typeof key}`);
465+
throw new TypeError(`Dictionary key must be a string, got ${typeof key}`);
466466
}
467467

468468
// Ensure we're not adding a TempObject to the dictionary

src/lib/remote-xpc/handshake-frames.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ class Struct {
2828
} else if (t === 'L') {
2929
total += 4;
3030
} else {
31-
throw new Error('Unsupported type: ' + t);
31+
throw new TypeError('Unsupported type: ' + t);
3232
}
3333
}
3434
return total;
3535
}
3636

3737
pack(...values: number[]): Buffer {
3838
if (values.length !== this.types.length) {
39-
throw new Error('Incorrect number of values to pack');
39+
throw new TypeError('Incorrect number of values to pack');
4040
}
4141
const buf = Buffer.alloc(this.byteLength());
4242
let offset = 0;
@@ -52,7 +52,7 @@ class Struct {
5252
buf.writeUInt32BE(v, offset);
5353
offset += 4;
5454
} else {
55-
throw new Error('Unsupported type: ' + t);
55+
throw new TypeError('Unsupported type: ' + t);
5656
}
5757
}
5858
return buf;

src/lib/remote-xpc/xpc-protocol.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export function decodeMessage(buffer: Buffer): XPCMessage {
208208
decodedValue === null ||
209209
Array.isArray(decodedValue)
210210
) {
211-
throw new Error('Expected dictionary as message body');
211+
throw new TypeError('Expected dictionary as message body');
212212
}
213213

214214
return { flags, id: msgId, body: decodedValue as XPCDictionary };
@@ -314,7 +314,7 @@ function encodeObject(writer: Writer, value: XPCValue): void {
314314
encodeDictionary(writer, value);
315315
return;
316316
}
317-
throw new Error('Unsupported type: ' + typeof value);
317+
throw new TypeError('Unsupported type: ' + typeof value);
318318
}
319319

320320
/**
@@ -374,7 +374,7 @@ function decodeObject(reader: Reader): XPCValue {
374374
return decodeDictionary(reader);
375375
// Note: fileTransfer type is not implemented here.
376376
default:
377-
throw new Error(`Unsupported xpc type: 0x${type.toString(16)}`);
377+
throw new TypeError(`Unsupported xpc type: 0x${type.toString(16)}`);
378378
}
379379
}
380380

0 commit comments

Comments
 (0)