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

error message failure when using abbreviated form of map #6513

Open
kieckhafer opened this issue Jan 29, 2020 · 1 comment
Open

error message failure when using abbreviated form of map #6513

kieckhafer opened this issue Jan 29, 2020 · 1 comment

Comments

@kieckhafer
Copy link
Member

kieckhafer commented Jan 29, 2020

When passing incorrect namespacing from the api, we expect an error message that alerts us to the incorrect namespace, such as:

{
  "errors": [
    {
      "message": "ID namespace must be reaction/group",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "accounts"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: ID namespace must be reaction/group",
            "    at file:///usr/local/src/app/node_modules/@reactioncommerce/api-utils/lib/decodeOpaqueIdForNamespace.js:16:72",
            "    at /usr/local/src/app/node_modules/ramda/src/internal/_curryN.js:37:27",
            "    at /usr/local/src/app/node_modules/ramda/src/internal/_arity.js:10:19",
            "    at file:///usr/local/src/app/src/core-services/account/resolvers/Query/accounts.js:22:54",
            "    at Array.map (<anonymous>)",
            "    at account (file:///usr/local/src/app/src/core-services/account/resolvers/Query/accounts.js:22:31)",
            "    at field.resolve (/usr/local/src/app/node_modules/graphql-extensions/dist/index.js:133:26)",
            "    at resolveFieldValueOrError (/usr/local/src/app/node_modules/graphql/execution/execute.js:467:18)",
            "    at resolveField (/usr/local/src/app/node_modules/graphql/execution/execute.js:434:16)",
            "    at executeFields (/usr/local/src/app/node_modules/graphql/execution/execute.js:275:18)"
          ]
        }
      }
    }
  ],
  "data": null
}

When calling a query from the API using map -
groupIds = opaqueGroupIds.map((opaqueGroupId) => decodeGroupOpaqueId(opaqueGroupId));

  • we get the correct error message.

However, when using the abbreviated version of map -
groupIds = opaqueGroupIds.map(decodeGroupOpaqueId);

  • we get an unhelpful error message with no real stack trace:
{
  "errors": [
    {
      "message": "Unexpected error value: 0",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "accounts"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Unexpected error value: 0",
            "    at asErrorInstance (/usr/local/src/app/node_modules/graphql/execution/execute.js:481:10)",
            "    at processTicksAndRejections (internal/process/task_queues.js:94:5)",
            "    at async Promise.all (index 0)"
          ]
        }
      }
    }
  ],
  "data": null
}

In theory, these two are the same and should provide the same error messaging.

@tuanvu0995
Copy link
Contributor

Hi @kieckhafer.

I think this issue is not a bug. Because your decodeGroupOpaqueId function gets second arguments with an instance of Error class.
But when you use the decodeGroupOpaqueId function with map like opaqueGroupIds.map(decodeGroupOpaqueId). It will pass the opaqueGroupId with the second argument as an index of the array (map will pass two arguments (element, index)).
In this case, I think you should use opaqueGroupIds.map((opaqueGroupId) => decodeGroupOpaqueId(opaqueGroupId)) instead the abbreviated version of the map.

See packages/api-utils/lib/decodeOpaqueIdForNamespace.js file.

Ref link: https://ramdajs.com/docs/#curry

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

No branches or pull requests

2 participants