Update datadog serializer to properly handle non-object errors#89
Closed
Update datadog serializer to properly handle non-object errors#89
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the datadog serializer where non-object errors (strings, arrays) were being destructured incorrectly, causing strings to be split into individual character properties. The fix ensures all non-object errors are properly wrapped in a standardized format.
- Adds type checking to handle non-object errors before destructuring
- Wraps non-object errors in a standardized
{details, kind}format - Updates tests to cover string and array error cases
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/index.js | Adds isPlainObject check and standardized error wrapping for non-objects |
| test/src/index.test.js | Expands test coverage for string and array error serialization scenarios |
| */ | ||
|
|
||
| function datadogErrorSerializer(error) { | ||
| if (!isPlainObject(error)) { |
There was a problem hiding this comment.
Consider using a more explicit type check. isPlainObject from lodash excludes many valid Error instances since Error objects are not plain objects. This could incorrectly wrap actual Error instances. Consider checking typeof error !== 'object' || error === null || Array.isArray(error) instead.
Suggested change
| if (!isPlainObject(error)) { | |
| if (typeof error !== 'object' || error === null || Array.isArray(error)) { |
Contributor
Author
|
Deprecated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR updates the datadog serializer to handle errors that are not objects. This aims to fix a bug where an error represented as a string would be destructured into an object containing all the elements of the string. Example:
foobarwould produce the following output:{ "0": "f", "1": "o", "2": "o", "3": "b", "4": "a", "5": "r" }With this fix the following error will be represented as follows:
{ "details": "foobar", "kind": "Error" }