Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Fix tests by :any-ing catch errors #559

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/healthcheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function healthcheck(): Promise<boolean> {
status.error('💔', 'Redis key @posthog-plugin-server/ping not found! Plugin server seems to be offline')
return false
}
} catch (error) {
} catch (error: any) {
status.error('💥', 'An unexpected error occurred:', error)
return false
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ switch (alternativeMode) {
status.info(`✅`, `Graphile migrations are now up to date!`)
await graphile.disconnectProducer()
process.exit(0)
} catch (error) {
} catch (error: any) {
status.error('🔴', 'Error running migrations for Graphile Worker!\n', error)
process.exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/ingestion-queues/celery-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CeleryQueue extends Base implements Queue {
this.handlers[name] = function registHandler(...args: any[]): Promise<any> {
try {
return Promise.resolve(handler(...args))
} catch (err) {
} catch (err: any) {
return Promise.reject(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/ingestion-queues/ingest-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function runInstrumentedFunction({
const timer = new Date()
try {
return await func(event)
} catch (error) {
} catch (error: any) {
status.info('🔔', error)
Sentry.captureException(error)
throw error
Expand Down
4 changes: 2 additions & 2 deletions src/main/ingestion-queues/kafka-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class KafkaQueue implements Queue {
eachBatch: async (payload) => {
try {
await this.eachBatch(payload)
} catch (error) {
} catch (error: any) {
status.info('💀', `Kafka batch of ${payload.batch.messages.length} events failed!`)
if (error.type === 'UNKNOWN_MEMBER_ID') {
status.info(
Expand Down Expand Up @@ -142,7 +142,7 @@ export class KafkaQueue implements Queue {
try {
await this.consumer.stop()
status.info('⏹', 'Kafka consumer stopped!')
} catch (error) {
} catch (error: any) {
status.error('⚠️', 'An error occurred while stopping Kafka queue:\n', error)
}
try {
Expand Down
6 changes: 3 additions & 3 deletions src/main/ingestion-queues/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function startQueues(
queues.ingestion = await startQueueKafka(server, piscina, mergedWorkerMethods)
}
return queues
} catch (error) {
} catch (error: any) {
status.error('💥', 'Failed to start event queue:\n', error)
throw error
}
Expand Down Expand Up @@ -93,7 +93,7 @@ function startQueueRedis(server: Hub, piscina: Piscina, workerMethods: WorkerMet
}
pauseQueueIfWorkerFull(() => celeryQueue.pause(), server, piscina)
await piscina?.run({ task: 'enqueueJob', args: { job } })
} catch (e) {
} catch (e: any) {
Sentry.captureException(e)
}
}
Expand Down Expand Up @@ -125,7 +125,7 @@ function startQueueRedis(server: Hub, piscina: Piscina, workerMethods: WorkerMet
try {
const checkAndPause = () => pauseQueueIfWorkerFull(() => celeryQueue.pause(), server, piscina)
await ingestEvent(server, workerMethods, event, checkAndPause)
} catch (e) {
} catch (e: any) {
Sentry.captureException(e)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/job-queues/concurrent/graphile-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class GraphileQueue extends JobQueueBase {
const pool = createPostgresPool(configOrDatabaseUrl, onError)
try {
await pool.query('select 1')
} catch (error) {
} catch (error: any) {
reject(error)
}
resolved = true
Expand Down
2 changes: 1 addition & 1 deletion src/main/job-queues/job-queue-consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function startJobQueueConsumer(server: Hub, piscina: Piscina): Prom
status.info('🔄', 'Job queue consumer lock acquired')
try {
await server.jobQueueManager.startConsumer(onJob)
} catch (error) {
} catch (error: any) {
try {
logOrThrowJobQueueError(server, error, `Can not start job queue consumer!`)
} catch {
Expand Down
4 changes: 2 additions & 2 deletions src/main/job-queues/job-queue-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class JobQueueManager implements JobQueue {
try {
await jobQueue.connectProducer()
status.info('🚶', `Connected to job queue producer "${jobQueueType}"`)
} catch (error) {
} catch (error: any) {
toRemove.add(jobQueue)
logOrThrowJobQueueError(
this.pluginsServer,
Expand All @@ -54,7 +54,7 @@ export class JobQueueManager implements JobQueue {
try {
await jobQueue.enqueue(job)
return
} catch (error) {
} catch (error: any) {
// if one fails, take the next queue
Sentry.captureException(error, {
extra: {
Expand Down
2 changes: 1 addition & 1 deletion src/main/pluginsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export async function startPluginsServer(
hub.lastActivityType = 'serverStart'

return serverInstance as ServerInstance
} catch (error) {
} catch (error: any) {
Sentry.captureException(error)
status.error('💥', 'Launchpad failure!', error)
void Sentry.flush().catch(() => null) // Flush Sentry in the background
Expand Down
6 changes: 3 additions & 3 deletions src/main/services/mmdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function decompressAndOpenMmdb(brotliContents: Buffer, filename: string):
)
try {
resolve(Reader.openBuffer(result))
} catch (e) {
} catch (e: any) {
reject(e)
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ async function distributableFetchAndInsertFreshMmdb(
const mmdb = await fetchAndInsertFreshMmdb(hub)
await hub.db.redisSet(MMDB_STATUS_REDIS_KEY, MMDBFileStatus.Idle)
return mmdb
} catch (e) {
} catch (e: any) {
// In case of an error mark the MMDB feature unavailable for an hour
await hub.db.redisSet(MMDB_STATUS_REDIS_KEY, MMDBFileStatus.Unavailable, 120)
status.error('❌', 'An error occurred during MMDB fetch and insert:', e)
Expand Down Expand Up @@ -230,7 +230,7 @@ export async function createMmdbServer(serverInstance: MMDBPrepServerInstance):
if (serverInstance.mmdb) {
try {
responseData = serverInstance.mmdb.city(partialData.toString().trim())
} catch (e) {
} catch (e: any) {
responseData = null
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/celery/broker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class Broker implements Pausable {
} else {
this.receiveSlow(resolve, queue, callback)
}
} catch (error) {
} catch (error: any) {
status.error('⚠️', 'An error occured in Celery broker:\n', error)
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/utils/db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class DB {
const response = await transaction(client)
await client.query('COMMIT')
return response
} catch (e) {
} catch (e: any) {
await client.query('ROLLBACK')
throw e
} finally {
Expand Down Expand Up @@ -210,7 +210,7 @@ export class DB {
return defaultValue
}
return value ? (jsonSerialize ? JSON.parse(value) : value) : null
} catch (error) {
} catch (error: any) {
if (error instanceof SyntaxError) {
// invalid JSON
return null
Expand Down Expand Up @@ -670,7 +670,7 @@ export class DB {
[target.id, source.id, target.team_id],
'updateDistinctIdPerson'
)
} catch (error) {
} catch (error: any) {
if (
error.message.includes(
'insert or update on table "posthog_persondistinctid" violates foreign key constraint'
Expand Down Expand Up @@ -890,7 +890,7 @@ export class DB {
)
}
})
} catch (error) {
} catch (error: any) {
// Throw further if not postgres error nr "23505" == "unique_violation"
// https://www.postgresql.org/docs/12/errcodes-appendix.html
if (error.code !== '23505') {
Expand Down Expand Up @@ -939,7 +939,7 @@ export class DB {
topic: KAFKA_PLUGIN_LOG_ENTRIES,
messages: [{ key: parsedEntry.id, value: Buffer.from(JSON.stringify(parsedEntry)) }],
})
} catch (e) {
} catch (e: any) {
captureException(e)
console.error(parsedEntry)
console.error(e)
Expand Down Expand Up @@ -972,7 +972,7 @@ export class DB {
values,
'insertPluginLogEntries'
)
} catch (e) {
} catch (e: any) {
captureException(e)
console.error(e)
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/db/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export async function createHub(

try {
await hub.jobQueueManager.connectProducer()
} catch (error) {
} catch (error: any) {
try {
logOrThrowJobQueueError(hub as Hub, error, `Can not start job queue producer!`)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/db/kafka-producer-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class KafkaProducerWrapper {
await this.producer.sendBatch({
topicMessages: messages,
})
} catch (err) {
} catch (err: any) {
// :TODO: Implement some retrying, https://github.com/PostHog/plugin-server/issues/511
this.statsd?.increment('query.kafka_send.failure')
throw err
Expand Down
4 changes: 2 additions & 2 deletions src/utils/redlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function startRedlock({
try {
lock = await lock.extend(lockTTL)
lockTimeout = setTimeout(extendLock, extendDelay)
} catch (error) {
} catch (error: any) {
status.error('🔴', `Redlock cannot extend lock "${resource}":\n`, error)
Sentry.captureException(error, { extra: { resource } })
weHaveTheLock = false
Expand All @@ -73,7 +73,7 @@ export async function startRedlock({
lockTimeout = setTimeout(extendLock, extendDelay)

await onLock?.()
} catch (error) {
} catch (error: any) {
if (stopped) {
return
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export function bufferToStream(binary: Buffer): Readable {
export async function getFileFromArchive(archive: Buffer, file: string): Promise<string | null> {
try {
return getFileFromZip(archive, file)
} catch (e) {
} catch (e: any) {
try {
return await getFileFromTGZ(archive, file)
} catch (e) {
} catch (e: any) {
throw new Error(`Could not read archive as .zip or .tgz`)
}
}
Expand Down Expand Up @@ -370,7 +370,7 @@ export async function tryTwice<T extends any>(
try {
const response = await Promise.race([timeout, callback()])
return response as T
} catch (error) {
} catch (error: any) {
Sentry.captureMessage(`Had to run twice: ${errorMessage}`)
// try one more time
return await callback()
Expand Down
2 changes: 1 addition & 1 deletion src/worker/ingestion/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function getFormattedMessage(
}
messageText = format(tokenizedMessage, ...values)
messageMarkdown = format(tokenizedMessage, ...markdownValues)
} catch (error) {
} catch (error: any) {
const [actionName, actionMarkdown] = getActionDetails(action, siteUrl, webhookType)
messageText = `⚠ Error: There are one or more formatting errors in the message template for action "${actionName}".`
messageMarkdown = `*⚠ Error: There are one or more formatting errors in the message template for action "${actionMarkdown}".*`
Expand Down
2 changes: 1 addition & 1 deletion src/worker/ingestion/ingest-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function ingestEvent(hub: Hub, event: PluginEvent): Promise<IngestE
// We don't want to return the inserted DB entry that `processEvent` returns.
// This response is passed to piscina and would be discarded anyway.
return { success: true }
} catch (e) {
} catch (e: any) {
status.info('🔔', e)
Sentry.captureException(e)
return { error: e.message }
Expand Down
16 changes: 8 additions & 8 deletions src/worker/ingestion/process-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class EventsProcessor {
})
try {
await this.handleIdentifyOrAlias(data['event'], properties, distinctId, teamId)
} catch (e) {
} catch (e: any) {
console.error('handleIdentifyOrAlias failed', e, data)
Sentry.captureException(e, { extra: { event: data } })
} finally {
Expand Down Expand Up @@ -170,7 +170,7 @@ export class EventsProcessor {
// timestamp and sent_at must both be in the same format: either both with or both without timezones
// otherwise we can't get a diff to add to now
return now.plus(DateTime.fromJSDate(new Date(data['timestamp'])).diff(sentAt))
} catch (error) {
} catch (error: any) {
status.error('⚠️', 'Error when handling timestamp:', error)
Sentry.captureException(error, { extra: { data, now, sentAt } })
}
Expand Down Expand Up @@ -292,7 +292,7 @@ export class EventsProcessor {
try {
await this.db.addDistinctId(oldPerson, distinctId)
// Catch race case when somebody already added this distinct_id between .get and .addDistinctId
} catch (error) {
} catch (error: any) {
Sentry.captureException(error)
// integrity error
if (retryIfFailed) {
Expand All @@ -307,7 +307,7 @@ export class EventsProcessor {
try {
await this.db.addDistinctId(newPerson, previousDistinctId)
// Catch race case when somebody already added this distinct_id between .get and .addDistinctId
} catch (error) {
} catch (error: any) {
Sentry.captureException(error)
// integrity error
if (retryIfFailed) {
Expand All @@ -324,7 +324,7 @@ export class EventsProcessor {
distinctId,
previousDistinctId,
])
} catch (error) {
} catch (error: any) {
Sentry.captureException(error)
// Catch race condition where in between getting and creating,
// another request already created this person
Expand Down Expand Up @@ -395,7 +395,7 @@ export class EventsProcessor {
while (true) {
try {
await this.db.moveDistinctIds(otherPerson, mergeInto)
} catch (error) {
} catch (error: any) {
Sentry.captureException(error, {
extra: { mergeInto, mergeIntoDistinctId, otherPerson, otherPersonDistinctId },
})
Expand All @@ -414,7 +414,7 @@ export class EventsProcessor {
try {
await this.db.deletePerson(otherPerson)
break // All OK, exiting retry loop
} catch (error) {
} catch (error: any) {
if (!(error instanceof DatabaseError)) {
throw error // Very much not OK, this is some completely unexpected error
}
Expand Down Expand Up @@ -615,7 +615,7 @@ export class EventsProcessor {
// Catch race condition where in between getting and creating, another request already created this user
try {
await this.db.createPerson(sentAt, {}, teamId, null, false, personUuid.toString(), [distinctId])
} catch (error) {
} catch (error: any) {
Sentry.captureException(error, { extra: { teamId, distinctId, sentAt, personUuid } })
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/worker/plugins/loadPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function loadPlugin(server: Hub, pluginConfig: PluginConfig): Promi
try {
const jsonBuffer = fs.readFileSync(configPath)
config = JSON.parse(jsonBuffer.toString())
} catch (e) {
} catch (e: any) {
pluginConfig.vm?.failInitialization!()
await processError(
server,
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function loadPlugin(server: Hub, pluginConfig: PluginConfig): Promi
if (json) {
try {
config = JSON.parse(json)
} catch (error) {
} catch (error: any) {
pluginConfig.vm?.failInitialization!()
await processError(server, pluginConfig, `Can not load plugin.json for ${pluginDigest(plugin)}`)
return false
Expand All @@ -88,7 +88,7 @@ export async function loadPlugin(server: Hub, pluginConfig: PluginConfig): Promi
`Tried using undownloaded remote ${pluginDigest(plugin)}, which is not supported!`
)
}
} catch (error) {
} catch (error: any) {
pluginConfig.vm?.failInitialization!()
await processError(server, pluginConfig, error)
}
Expand Down
Loading