Our privacy policy says we "maintain a GDPR audit trail of privacy-related actions on your account". The code behind that sentence is one function, logAuditAction, and the most important thing about it is in its catch block.

The shape

export async function logAuditAction(params: AuditLogParams): Promise<void> { try { await db.insert(auditLogsTable).values({ ... }); } catch (error) { // Log error but don't fail the main operation if (process.env.NODE_ENV === 'development') { console.error('Failed to log audit action:', error); } } } 

The first half of that is a decision I agree with. If someone asks to export their data and the audit row cannot be written, you do not want the export to fail with it. The audit is a record of the action, not part of the action, so the action goes ahead and the logger never throws. There are 14 call sites across the app (data export, account deletion, consent changes, profile and onboarding edits, calendar connect and disconnect, interview and game-session deletes, and operator changes to an account), and every one of them awaits it and carries on.

The second half

Look at the condition. The error is printed only when NODE_ENV is development. In production, which is where the table matters, a failed insert leaves no trace anywhere: no log line, no Sentry event, no counter. The function returns undefined either way, so the caller cannot tell a written row from a lost one.

The rest of the code base has the tool for this. logError in our logger prints always, because its comment says "Log errors (always)". The audit logger does not use it. My guess at how it got this way is that the first draft logged in development to keep test output readable, and the guard stayed because it looked like the same pattern as the debug helpers beside it.

What this means in practice:

  • If the table is unreachable for an hour, an hour of consent changes and deletions have no records, and nothing in monitoring says so.
  • If a schema change breaks the insert, every audit write fails from that deploy on, and it looks identical to a quiet day.
  • The only evidence would be a gap, found months later by someone asking for an export and noticing it is thin.

The policy sentence promises a trail. A trail that can silently stop is a weaker promise than the one written.

The fix is one line, with a decision in it

Report the failure, keep swallowing it:

} catch (error) { logError('[audit] write failed', params.action, params.resourceType, error); } 

That keeps the property I wanted (the main operation never fails because of the log) and makes a failure show up in the place errors already go. The decision that is worth thinking about is what to put in the message. Log the action name and the resource type, which are a fixed vocabulary, and not params.details, which can carry personal data. An error report is a copy of whatever you put in it.

For the stricter case, an operation where the record is the point (an account deletion, for instance), there is a second option: a variant that returns a boolean, or throws, so the caller can decide. Most of our 14 call sites are happy with fire-and-forget. One or two are not, and they are the ones I would look at first.

See it

The sentence in question is on the privacy page: look for "Maintain a GDPR audit trail" in the list of what we do with your data, and further down the line that says audit logs are deleted when you delete your account. Those two statements are why I would want a failed write to be visible. For the other half of the story, the terms and the cookie policy are the neighbouring documents that make claims about the code in the same way.

I have not changed the function, and I could not show you the failure live without breaking something on purpose. The code above is quoted from the repository with its comment, and the behaviour follows from reading it.

CogniPrep is a practice site for employer assessments, and the homepage is the place to start.