Skip to content

Commit 5453ce6

Browse files
committed
ErrorInfo.cause: must be an errorinfo if present, not a string
ErrorInfo.cause should never have been permitted to be an Error or a string in the typings; if present it must be an ErrorInfo (spec TI1). AFAICS it's never a string, there were some places where it could be an Error which I've fixed.
1 parent 8ba5b64 commit 5453ce6

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

ably.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,7 +3693,7 @@ export declare class ErrorInfo extends Error {
36933693
/**
36943694
* The underlying cause of the error, where applicable.
36953695
*/
3696-
cause?: string | Error | ErrorInfo;
3696+
cause?: ErrorInfo;
36973697

36983698
/**
36993699
* Construct an ErrorInfo object.
@@ -3703,5 +3703,5 @@ export declare class ErrorInfo extends Error {
37033703
* @param statusCode - HTTP Status Code corresponding to this error.
37043704
* @param cause - The underlying cause of the error.
37053705
*/
3706-
constructor(message: string, code: number, statusCode: number, cause?: string | Error | ErrorInfo);
3706+
constructor(message: string, code: number, statusCode: number, cause?: ErrorInfo);
37073707
}

src/common/lib/client/realtimechannel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class RealtimeChannel extends EventEmitter {
7777
attachSerial: string | null | undefined;
7878
channelSerial: string | null | undefined;
7979
};
80-
errorReason: ErrorInfo | string | null;
80+
errorReason: ErrorInfo | null;
8181
_mode = 0;
8282
_attachResume: boolean;
8383
_decodingContext: EncodingDecodingContext;

src/common/lib/types/errorinfo.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as API from '../../../../ably';
55
export interface IPartialErrorInfo extends Error {
66
code: number | null;
77
statusCode?: number;
8-
cause?: string | Error | ErrorInfo;
8+
cause?: ErrorInfo | PartialErrorInfo;
99
href?: string;
1010
}
1111

@@ -35,10 +35,10 @@ export interface IConvertibleToPartialErrorInfo {
3535
export default class ErrorInfo extends Error implements IPartialErrorInfo, API.ErrorInfo {
3636
code: number;
3737
statusCode: number;
38-
cause?: string | Error | ErrorInfo;
38+
cause?: ErrorInfo;
3939
href?: string;
4040

41-
constructor(message: string, code: number, statusCode: number, cause?: string | Error | ErrorInfo) {
41+
constructor(message: string, code: number, statusCode: number, cause?: ErrorInfo) {
4242
super(message);
4343
if (typeof Object.setPrototypeOf !== 'undefined') {
4444
Object.setPrototypeOf(this, ErrorInfo.prototype);
@@ -68,10 +68,10 @@ export default class ErrorInfo extends Error implements IPartialErrorInfo, API.E
6868
export class PartialErrorInfo extends Error implements IPartialErrorInfo {
6969
code: number | null;
7070
statusCode?: number;
71-
cause?: string | Error | ErrorInfo;
71+
cause?: ErrorInfo | PartialErrorInfo;
7272
href?: string;
7373

74-
constructor(message: string, code: number | null, statusCode?: number, cause?: string | Error | ErrorInfo) {
74+
constructor(message: string, code: number | null, statusCode?: number, cause?: ErrorInfo | PartialErrorInfo) {
7575
super(message);
7676
if (typeof Object.setPrototypeOf !== 'undefined') {
7777
Object.setPrototypeOf(this, PartialErrorInfo.prototype);

src/platform/nodejs/lib/util/crypto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ var createCryptoClass = function (bufferUtils: typeof BufferUtils) {
180180
try {
181181
return generateRandom((keyLength || DEFAULT_KEYLENGTH) / 8);
182182
} catch (err) {
183-
throw new ErrorInfo('Failed to generate random key: ' + (err as Error).message, 500, 50000, err as Error);
183+
throw new ErrorInfo('Failed to generate random key: ' + (err as Error).message, 500, 50000);
184184
}
185185
}
186186

src/platform/web/lib/util/crypto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ var createCryptoClass = function (config: IPlatformConfig, bufferUtils: typeof B
143143
try {
144144
return config.getRandomArrayBuffer((keyLength || DEFAULT_KEYLENGTH) / 8);
145145
} catch (err) {
146-
throw new ErrorInfo('Failed to generate random key: ' + (err as Error).message, 400, 50000, err as Error);
146+
throw new ErrorInfo('Failed to generate random key: ' + (err as Error).message, 400, 50000);
147147
}
148148
}
149149

src/plugins/push/getW3CDeviceDetails.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export async function getW3CPushDeviceDetails(machine: ActivationStateMachine) {
8484
machine.handleEvent(new GotPushDeviceDetails());
8585
} catch (err) {
8686
machine.handleEvent(
87-
new GettingPushDeviceDetailsFailed(new ErrorInfo('Failed to register service worker', 50000, 500, err as Error)),
87+
new GettingPushDeviceDetailsFailed(
88+
new ErrorInfo('Failed to register service worker: ' + (err as Error).message, 50000, 500),
89+
),
8890
);
8991
}
9092
}

0 commit comments

Comments
 (0)