Skip to content

Commit

Permalink
fix: no console logging on schema (#19349)
Browse files Browse the repository at this point in the history
* fix: no console logging of schema validation

* move validation behind a (n unused) boolean check

* Fix
  • Loading branch information
pauldambra authored Dec 15, 2023
1 parent a1c6ec9 commit 7cd9e14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 7 additions & 6 deletions ee/frontend/mobile-replay/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { eventWithTime } from '@rrweb/types'
import { captureException } from '@sentry/react'
import { captureException, captureMessage } from '@sentry/react'
import Ajv, { ErrorObject } from 'ajv'

import { mobileEventWithTime } from './mobile.types'
Expand Down Expand Up @@ -36,7 +36,7 @@ function couldBeEventWithTime(x: unknown): x is eventWithTime | mobileEventWithT
return typeof x === 'object' && x !== null && 'type' in x && 'timestamp' in x
}

export function transformEventToWeb(event: unknown): eventWithTime {
export function transformEventToWeb(event: unknown, validateTransformation?: boolean): eventWithTime {
// the transformation needs to never break a recording itself
// so, we default to returning what we received
// replacing it only if there's a valid transformation
Expand All @@ -46,11 +46,13 @@ export function transformEventToWeb(event: unknown): eventWithTime {
const transformer = transformers[event.type]
if (transformer) {
const transformed = transformer(event)
validateAgainstWebSchema(transformed)
if (validateTransformation) {
validateAgainstWebSchema(transformed)
}
result = transformed
}
} else {
console.warn(`No type in event: ${JSON.stringify(event)}`)
captureMessage(`No type in event`, { extra: { event } })
}
} catch (e) {
captureException(e, { extra: { event } })
Expand All @@ -70,8 +72,7 @@ export function validateAgainstWebSchema(data: unknown): boolean {
const validationResult = webSchemaValidator(data)
if (!validationResult) {
// we are passing all data through this validation now and don't know how safe the schema is
console.error(webSchemaValidator.errors)
captureException(new Error('transformation did not match schema'), {
captureMessage('transformation did not match schema', {
extra: { data, errors: webSchemaValidator.errors },
})
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/@posthog/ee/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { eventWithTime } from '@rrweb/types'
export type PostHogEE = {
enabled: boolean
mobileReplay?: {
// defined as unknown while the mobileEventWithTime type is in the ee folder
transformEventToWeb(x: unknown): eventWithTime | null
transformEventToWeb(x: unknown, validateTransformation?: boolean): eventWithTime | null
transformToWeb(x: unknown[]): eventWithTime[]
}
}

0 comments on commit 7cd9e14

Please sign in to comment.