Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim objects that are serialized by err and errWithCause #141

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

zbrydon
Copy link
Contributor

@zbrydon zbrydon commented Jul 16, 2024

Purpose

This test fails in master with the following output, which can result in some quite nasty logs... I caught this in a few logs that were logging entire html documents 🫠

image

Approach

Trim the returned objected from both the err and errWithCause serializers with the desired formatting options.

@zbrydon zbrydon requested a review from a team July 16, 2024 06:40
Copy link

changeset-bot bot commented Jul 16, 2024

⚠️ No Changeset found

Latest commit: 26f7f54

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ConradLang ConradLang merged commit 54f16e1 into master Jul 16, 2024
4 checks passed
@ConradLang ConradLang deleted the fix-error-truncating branch July 16, 2024 23:22
Copy link
Member

@72636c 72636c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this down @zbrydon!

(error: unknown): unknown =>
trimmer({
depth: opts.maxObjectDepth ?? 4,
})(serializer(error as Error));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some way we can avoid this type assertion? 🤔

opts: FormatterOptions,
): SerializerFn =>
(error: unknown): unknown =>
trimmer({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any value in sharing a trimmer across the serializers? (I have no clue.)

): SerializerFn =>
(error: unknown): unknown =>
trimmer({
depth: opts.maxObjectDepth ?? 4,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Nitpick: can we set the default (4) in one spot?

  2. Could some engineers be relying on the fact that they can read deeply nested error information, e.g. to review a HTTP request and response body and figure out what caused a HTTP 400? Not to say we should encourage this practice, but it may be an easy out that is available today, and I wonder if 4 is still a reasonable global default in this light.

    On the topic of release, I'd almost err toward a major version here.

depth: opts.maxObjectDepth ?? 4,
})(serializer(error as Error));

export const createSerializers = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like @samchungy's question of whether we should apply this to all serialisers. Would all also include user-provided ones? 🤔

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.

4 participants