Skip to content

Commit

Permalink
Remove setError completely.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkaemming committed Nov 21, 2023
1 parent 9124858 commit e96da9d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 31 deletions.
14 changes: 10 additions & 4 deletions plugin-server/src/utils/db/error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { PluginEvent, PostHogEvent, ProcessedPluginEvent } from '@posthog/plugin-scaffold'
import { captureException } from '@sentry/node'

import { Hub, PluginConfig, PluginError } from '../../types'
import { setError } from './sql'
import { Hub, PluginConfig, PluginError, PluginLogEntrySource, PluginLogEntryType } from '../../types'

export class DependencyUnavailableError extends Error {
constructor(message: string, dependencyName: string, error: Error) {
Expand Down Expand Up @@ -47,7 +46,7 @@ export async function processError(
throw error
}

const errorJson: PluginError =
const pluginError: PluginError =
typeof error === 'string'
? {
message: error,
Expand All @@ -61,7 +60,14 @@ export async function processError(
event: event,
}

await setError(server, errorJson, pluginConfig)
await server.db.queuePluginLogEntry({
pluginConfig,
source: PluginLogEntrySource.Plugin,
type: PluginLogEntryType.Error,
message: pluginError.stack ?? pluginError.message,
instanceId: server.instanceId,
timestamp: pluginError.time,
})
}

export function cleanErrorStackTrace(stack: string | undefined): string | undefined {
Expand Down
26 changes: 1 addition & 25 deletions plugin-server/src/utils/db/sql.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import {
Hub,
Plugin,
PluginAttachmentDB,
PluginCapabilities,
PluginConfig,
PluginConfigId,
PluginError,
PluginLogEntrySource,
PluginLogEntryType,
} from '../../types'
import { Hub, Plugin, PluginAttachmentDB, PluginCapabilities, PluginConfig, PluginConfigId } from '../../types'
import { PostgresUse } from './postgres'

function pluginConfigsInForceQuery(specificField?: keyof PluginConfig): string {
Expand Down Expand Up @@ -115,20 +105,6 @@ export async function setPluginCapabilities(
)
}

export async function setError(hub: Hub, pluginError: PluginError | null, pluginConfig: PluginConfig): Promise<void> {
// TODO: pluginError can likely be required now, but need to check call sites more thoroughly to ensure that's the case.
if (pluginError) {
await hub.db.queuePluginLogEntry({
pluginConfig,
source: PluginLogEntrySource.Plugin,
type: PluginLogEntryType.Error,
message: pluginError.stack ?? pluginError.message,
instanceId: hub.instanceId,
timestamp: pluginError.time,
})
}
}

export async function disablePlugin(hub: Hub, pluginConfigId: PluginConfigId): Promise<void> {
await hub.db.postgres.query(
PostgresUse.COMMON_WRITE,
Expand Down
1 change: 0 additions & 1 deletion plugin-server/tests/helpers/sqlMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ export const getPluginConfigRows = s.getPluginConfigRows as unknown as jest.Mock
export const setPluginCapabilities = s.setPluginCapabilities as unknown as jest.MockedFunction<
UnPromisify<typeof s.setPluginCapabilities>
>
export const setError = s.setError as unknown as jest.MockedFunction<UnPromisify<typeof s.setError>>
export const disablePlugin = s.disablePlugin as unknown as jest.MockedFunction<UnPromisify<void>>
1 change: 0 additions & 1 deletion plugin-server/tests/utils/retries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { PromiseManager } from '../../src/worker/vm/promise-manager'

jest.useFakeTimers()
jest.spyOn(global, 'setTimeout')
jest.mock('../../src/utils/db/error') // Mocking setError which we don't need in tests

const mockHub: Hub = {
instanceId: new UUID('F8B2F832-6639-4596-ABFC-F9664BC88E84'),
Expand Down

0 comments on commit e96da9d

Please sign in to comment.