Skip to content

ref(service): Share parseJson, isObject, and httpError - #62

Merged
dcramer merged 1 commit into
mainfrom
refactor/parse-json
Nov 5, 2026
Merged

dcramer merged 1 commit into
mainfrom
refactor/parse-json

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

No behavior change.

  • One parseJson in json-strings.ts. A separate parseJsonSkipBom skips a leading byte order mark, and only secrets.ts uses it, as before. The key code never skipped the BOM, so it still doesn't.
  • isObject is shared.
  • httpError moved to errors.ts. bodies.ts, recorder.ts and secrets.ts use it.

Same output as main: a side-by-side run on about 24,000 cases (BOMs, empty and invalid bodies, scalars, __proto__, lone surrogates, \u escapes, duplicate keys, form and event-stream content types) gave 0 differences in keyRequest, usageAttributes, redactRequestWith, redactRequestUrl, redactFields and the learned credential list. The pinned key tests pass with no edits.

Reviewed independently. pnpm check passes and knip is clean.

via @dcramer.

--

View Session [Sentry]

`request-key.ts` and `usage.ts` each had a copy of `parseJson`, and
`json-strings.ts` had a third that also skips a byte order mark.
`usage.ts` and `secrets.ts` each had `isObject`. `bodies.ts` had
`httpError`, and `recorder.ts` and `secrets.ts` built the same error by
hand.

- `json-strings.ts` now has `parseJson` (no BOM skip), `parseJsonSkipBom`
  (for `secrets.ts`, as before), and `isObject`.
- `errors.ts` now has `httpError`. `bodies.ts`, `recorder.ts`, and
  `secrets.ts` use it.

The key keeps the parse without the BOM skip, so a body that starts with
a BOM keys as text, as before. `JSON.parse("")` throws, so the old
`body ? JSON.parse(body) : undefined` of `request-key.ts` gives the same
result. The pinned key tests pass without a change, and a randomized
compare of 30,000 bodies (JSON, BOM, cut JSON, forms, streams, thinking
blocks, known values) against main gives the same `keyRequest`,
`usageAttributes`, `redactRequest`, and `redactFields` results.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
@dcramer
dcramer marked this pull request as ready for review November 5, 2026 19:34
@dcramer
dcramer merged commit dceb3ed into main Nov 5, 2026
16 checks passed
@dcramer
dcramer deleted the refactor/parse-json branch November 5, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant