Skip to content

Conversation

@Dakrs
Copy link
Contributor

@Dakrs Dakrs commented Aug 4, 2025

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: foobar would 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"
}

Copilot AI review requested due to automatic review settings August 4, 2025 11:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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)) {
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

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)) {

Copilot uses AI. Check for mistakes.
@Dakrs
Copy link
Contributor Author

Dakrs commented Sep 23, 2025

Deprecated.

@Dakrs Dakrs closed this Sep 23, 2025
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.

2 participants