Skip to content

Commit 740c665

Browse files
committed
chore: fix server-core-integration linter errors
1 parent fe24326 commit 740c665

File tree

9 files changed

+18
-16
lines changed

9 files changed

+18
-16
lines changed

packages/server-core-integration/examples/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
PeripheralDeviceCategory,
55
PeripheralDeviceType,
66
} from '@sofie-automation/shared-lib/dist/peripheralDevice/peripheralDeviceAPI'
7-
import { CoreConnection, PeripheralDevicePubSub, PeripheralDevicePubSubCollectionsNames } from '../src/index'
7+
import { CoreConnection, PeripheralDevicePubSub, PeripheralDevicePubSubCollectionsNames } from '../src/index.js'
88

99
const core = new CoreConnection({
1010
deviceId: protectString('ExampleDevice'),

packages/server-core-integration/src/__tests__/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ describe('coreConnection', () => {
368368

369369
// temporary scramble the ddp host:
370370
options.host = '127.0.0.9'
371-
core.ddp.ddpClient && core.ddp.ddpClient.resetOptions(options)
371+
core.ddp.ddpClient?.resetOptions(options)
372372
// Force-close the socket:
373373
core.ddp.ddpClient?.socket?.close()
374374

@@ -379,7 +379,7 @@ describe('coreConnection', () => {
379379

380380
// restore ddp host:
381381
options.host = '127.0.0.1'
382-
core.ddp.ddpClient && core.ddp.ddpClient.resetOptions(options)
382+
core.ddp.ddpClient?.resetOptions(options)
383383
await wait(1000)
384384
// should have reconnected by now
385385

packages/server-core-integration/src/lib/CoreConnectionChild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class CoreConnectionChild<
147147
*/
148148
async callMethodRaw(methodName: string, attrs: Array<any>): Promise<any> {
149149
if (this._destroyed) {
150-
throw 'callMethod: CoreConnection has been destroyed'
150+
throw new Error('callMethod: CoreConnection has been destroyed')
151151
}
152152

153153
return this._methodQueue.callMethodRaw(methodName, attrs)

packages/server-core-integration/src/lib/__tests__/watchDog.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('watchDog', () => {
1919

2020
return new Promise<void>((resolver, reject) => {
2121
if (coreIsHappy) resolver()
22-
else if (coreReplies) reject()
22+
else if (coreReplies) reject(new Error('Core is not happy'))
2323
})
2424
})
2525
const exitFcn = jest.fn(() => {

packages/server-core-integration/src/lib/coreConnection.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
PeripheralDevicePubSubTypes,
2828
} from '@sofie-automation/shared-lib/dist/pubsub/peripheralDevice'
2929

30-
// eslint-disable-next-line @typescript-eslint/no-var-requires
3130
const PkgInfo = require('../../package.json')
3231

3332
export interface CoreCredentials {
@@ -272,7 +271,7 @@ export class CoreConnection<
272271
*/
273272
async callMethodRaw(methodName: string, attrs: Array<any>): Promise<any> {
274273
if (this._destroyed) {
275-
throw 'callMethod: CoreConnection has been destroyed'
274+
throw new Error('callMethod: CoreConnection has been destroyed')
276275
}
277276

278277
if (!this._methodQueue) throw new Error('Connection is not ready to call methods')
@@ -444,7 +443,7 @@ export class CoreConnection<
444443
} else {
445444
i++
446445
if (i > 50) {
447-
reject()
446+
reject(new Error('Watchdog ping timeout'))
448447
} else {
449448
setTimeout(checkPingReply, 300)
450449
}

packages/server-core-integration/src/lib/ddpClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export class DDPClient extends EventEmitter<DDPClientEvents> {
405405
constructor(opts?: DDPConnectorOptions) {
406406
super()
407407

408-
opts || (opts = { host: '127.0.0.1', port: 3000, tlsOpts: {} })
408+
opts = opts || { host: '127.0.0.1', port: 3000, tlsOpts: {} }
409409

410410
this.resetOptions(opts)
411411
this.ddpVersionInt = opts.ddpVersion || '1'
@@ -810,7 +810,7 @@ export class DDPClient extends EventEmitter<DDPClientEvents> {
810810

811811
close(): void {
812812
this.isClosing = true
813-
this.socket && this.socket.close() // with mockJS connection, might not get created
813+
this.socket?.close() // with mockJS connection, might not get created
814814
this.removeAllListeners('connected')
815815
this.removeAllListeners('failed')
816816
}

packages/server-core-integration/src/lib/methods.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,25 @@ export class ConnectionMethodsQueue {
7676
async callMethodRaw(methodName: string, attrs: Array<any>): Promise<any> {
7777
return new Promise((resolve, reject) => {
7878
if (!methodName) {
79-
reject('callMethod: argument missing: methodName')
79+
reject(new Error('callMethod: argument missing: methodName'))
8080
return
8181
}
8282

8383
const fullAttrs = [this._credentials.deviceId, this._credentials.deviceToken].concat(attrs || [])
8484

8585
this._timeLastMethodCall = Date.now()
8686
if (!this._ddp.ddpClient) {
87-
reject('callMehod: DDP client has not been initialized')
87+
reject(new Error('callMehod: DDP client has not been initialized'))
8888
return
8989
}
9090
const timeout = setTimeout(() => {
9191
// Timeout
9292
console.error(`Timeout "${methodName}"`)
9393
console.error(JSON.stringify(fullAttrs))
9494
reject(
95-
`Timeout when calling method "${methodName}", arguments: ${JSON.stringify(fullAttrs).slice(0, 200)}`
95+
new Error(
96+
`Timeout when calling method "${methodName}", arguments: ${JSON.stringify(fullAttrs).slice(0, 200)}`
97+
)
9698
)
9799
}, 10 * 1000) // 10 seconds
98100
this._ddp.ddpClient.call(methodName, fullAttrs, (err: DDPError | undefined, result: any) => {
@@ -109,6 +111,7 @@ export class ConnectionMethodsQueue {
109111
}
110112
}
111113
}
114+
112115
reject(err)
113116
} else {
114117
resolve(result)

packages/server-core-integration/src/lib/subscriptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class SubscriptionsHelper<PubSubTypes> {
4444
const orgError = new Error()
4545
return new Promise((resolve, reject) => {
4646
if (!this.#ddp.ddpClient) {
47-
reject('subscribe: DDP client is not initialized')
47+
reject(new Error('subscribe: DDP client is not initialized'))
4848
return
4949
}
5050
try {
@@ -67,7 +67,7 @@ export class SubscriptionsHelper<PubSubTypes> {
6767
unprotectString(existingSubscriptionId)
6868
)
6969
} catch (e) {
70-
reject(e)
70+
reject(e instanceof Error ? e : new Error('subscribe failed: ' + e))
7171
}
7272
})
7373
}

packages/server-core-integration/src/lib/watchDog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class WatchDog extends EventEmitter<WatchDogEvents> {
8585
if (this.listenerCount('exit') > 0) {
8686
this.emit('exit')
8787
} else {
88-
// eslint-disable-next-line no-process-exit
88+
// eslint-disable-next-line n/no-process-exit
8989
process.exit(42)
9090
}
9191
}, 5000)

0 commit comments

Comments
 (0)