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

Undesired stripping of error texts causes by colons (:) #2153

Closed
seminarian opened this issue Apr 28, 2023 · 2 comments
Closed

Undesired stripping of error texts causes by colons (:) #2153

seminarian opened this issue Apr 28, 2023 · 2 comments
Assignees
Labels
type: bug 🐛 Something isn't working

Comments

@seminarian
Copy link
Contributor

Describe the bug
When returning an error message (or throwing an exception) all text in the message is stripped up until the first colon :. Subsequent colons are replaced with a .

To Reproduce
Steps to reproduce the behavior:

  1. Add following custom field to the config:
    config.customFields.Product.push({
      name: 'sustainabilityClass',
      label: [
        {
          languageCode: LanguageCode.en,
          value: 'Sustainability class',
        },
      ],
      type: 'string',
      validate: () =>
        'All text before the first colon: removed but after: replaced by a dot',
    });
  1. Run the server and go to ADMIN UI and for a product try to update the sustainabilityClass custom field, response:
    image
Response from developer tools { "errors": [{ "stack": "Error: All text before the first colon: removed but after: replaced by a dot\n at validateCustomFunction (/home/pieter/projects/ecommerce-engine/node_modules/@vendure/core/src/api/common/validate-custom-field-value.ts:77:19)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async Object.validateCustomFieldValue (/home/pieter/projects/ecommerce-engine/node_modules/@vendure/core/src/api/common/validate-custom-field-value.ts:43:5)\n at async ValidateCustomFieldsInterceptor.validateCustomFieldsObject (/home/pieter/projects/ecommerce-engine/node_modules/@vendure/core/src/api/middleware/validate-custom-fields-interceptor.ts:124:17)\n at async ValidateCustomFieldsInterceptor.validateInput (/home/pieter/projects/ecommerce-engine/node_modules/@vendure/core/src/api/middleware/validate-custom-fields-interceptor.ts:92:17)\n at async ValidateCustomFieldsInterceptor.intercept (/home/pieter/projects/ecommerce-engine/node_modules/@vendure/core/src/api/middleware/validate-custom-fields-interceptor.ts:62:33)", "message": " removed but after. replaced by a dot", "name": "GraphQLError", "locations": [{ "line": 2, "column": 3 }], "path": ["updateProduct"], "nodes": [{ "kind": "Field", "name": { "kind": "Name", "value": "updateProduct", "loc": { "start": 104, "end": 117 } }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input", "loc": { "start": 118, "end": 123 } }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input", "loc": { "start": 126, "end": 131 } }, "loc": { "start": 125, "end": 131 } }, "loc": { "start": 118, "end": 131 } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "FragmentSpread", "name": { "kind": "Name", "value": "ProductDetail", "loc": { "start": 142, "end": 155 } }, "directives": [], "loc": { "start": 139, "end": 155 } }, { "kind": "Field", "name": { "kind": "Name", "value": "variantList", "loc": { "start": 160, "end": 171 } }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "options", "loc": { "start": 172, "end": 179 } }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "variantListOptions", "loc": { "start": 182, "end": 200 } }, "loc": { "start": 181, "end": 200 } }, "loc": { "start": 172, "end": 200 } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "items", "loc": { "start": 210, "end": 215 } }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "FragmentSpread", "name": { "kind": "Name", "value": "ProductVariant", "loc": { "start": 229, "end": 243 } }, "directives": [], "loc": { "start": 226, "end": 243 } }, { "kind": "Field", "name": { "kind": "Name", "value": "__typename", "loc": { "start": 252, "end": 262 } }, "arguments": [], "directives": [], "loc": { "start": 252, "end": 262 } }], "loc": { "start": 216, "end": 270 } }, "loc": { "start": 210, "end": 270 } }, { "kind": "Field", "name": { "kind": "Name", "value": "totalItems", "loc": { "start": 277, "end": 287 } }, "arguments": [], "directives": [], "loc": { "start": 277, "end": 287 } }, { "kind": "Field", "name": { "kind": "Name", "value": "__typename", "loc": { "start": 294, "end": 304 } }, "arguments": [], "directives": [], "loc": { "start": 294, "end": 304 } }], "loc": { "start": 202, "end": 310 } }, "loc": { "start": 160, "end": 310 } }, { "kind": "Field", "name": { "kind": "Name", "value": "__typename", "loc": { "start": 315, "end": 325 } }, "arguments": [], "directives": [], "loc": { "start": 315, "end": 325 } }], "loc": { "start": 133, "end": 329 } }, "loc": { "start": 104, "end": 329 } }], "source": { "body": "mutation UpdateProduct($input: UpdateProductInput!, $variantListOptions: ProductVariantListOptions) {\n updateProduct(input: $input) {\n ...ProductDetail\n variantList(options: $variantListOptions) {\n items {\n ...ProductVariant\n __typename\n }\n totalItems\n __typename\n }\n __typename\n }\n}\n\nfragment ProductDetail on Product {\n id\n createdAt\n updatedAt\n enabled\n languageCode\n name\n slug\n description\n featuredAsset {\n ...Asset\n __typename\n }\n assets {\n ...Asset\n __typename\n }\n translations {\n id\n languageCode\n name\n slug\n description\n __typename\n }\n optionGroups {\n ...ProductOptionGroup\n __typename\n }\n facetValues {\n id\n code\n name\n facet {\n id\n name\n __typename\n }\n __typename\n }\n channels {\n id\n code\n __typename\n }\n customFields {\n upsellVariants {\n enabled\n trackInventory\n stockOnHand\n stockAllocated\n outOfStockThreshold\n useGlobalOutOfStockThreshold\n id\n productId\n createdAt\n updatedAt\n languageCode\n sku\n name\n price\n currencyCode\n priceWithTax\n stockLevel\n __typename\n }\n dimensionsCm\n dimensionsInch\n numberOfPhotos\n numberOfCards\n sustainabilityClass\n paperTypeClass\n finishingClass\n __typename\n }\n __typename\n}\n\nfragment ProductOptionGroup on ProductOptionGroup {\n id\n createdAt\n updatedAt\n code\n languageCode\n name\n translations {\n id\n languageCode\n name\n __typename\n }\n __typename\n}\n\nfragment Asset on Asset {\n id\n createdAt\n updatedAt\n name\n fileSize\n mimeType\n type\n preview\n source\n width\n height\n focalPoint {\n x\n y\n __typename\n }\n __typename\n}\n\nfragment ProductVariant on ProductVariant {\n id\n createdAt\n updatedAt\n enabled\n languageCode\n name\n price\n currencyCode\n priceWithTax\n stockOnHand\n stockAllocated\n trackInventory\n outOfStockThreshold\n useGlobalOutOfStockThreshold\n taxRateApplied {\n id\n name\n value\n __typename\n }\n taxCategory {\n id\n name\n __typename\n }\n sku\n options {\n ...ProductOption\n __typename\n }\n facetValues {\n id\n code\n name\n facet {\n id\n name\n __typename\n }\n __typename\n }\n featuredAsset {\n ...Asset\n __typename\n }\n assets {\n ...Asset\n __typename\n }\n translations {\n id\n languageCode\n name\n __typename\n }\n channels {\n id\n code\n __typename\n }\n customFields {\n upsellVariantsOverride {\n enabled\n trackInventory\n stockOnHand\n stockAllocated\n outOfStockThreshold\n useGlobalOutOfStockThreshold\n id\n productId\n createdAt\n updatedAt\n languageCode\n sku\n name\n price\n currencyCode\n priceWithTax\n stockLevel\n __typename\n }\n numberOfPhotosOverride\n numberOfCardsOverride\n dimensionsCmOverride\n dimensionsInchOverride\n productSpecs\n __typename\n }\n __typename\n}\n\nfragment ProductOption on ProductOption {\n id\n createdAt\n updatedAt\n code\n languageCode\n name\n groupId\n translations {\n id\n languageCode\n name\n __typename\n }\n __typename\n}\n", "name": "GraphQL request", "locationOffset": { "line": 1, "column": 1 } }, "positions": [104], "originalError": { "stack": "Error: All text before the first colon: removed but after: replaced by a dot\n at validateCustomFunction (/home/pieter/projects/ecommerce-engine/node_modules/@vendure/core/src/api/common/validate-custom-field-value.ts:77:19)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async Object.validateCustomFieldValue (/home/pieter/projects/ecommerce-engine/node_modules/@vendure/core/src/api/common/validate-custom-field-value.ts:43:5)\n at async ValidateCustomFieldsInterceptor.validateCustomFieldsObject (/home/pieter/projects/ecommerce-engine/node_modules/@vendure/core/src/api/middleware/validate-custom-fields-interceptor.ts:124:17)\n at async ValidateCustomFieldsInterceptor.validateInput (/home/pieter/projects/ecommerce-engine/node_modules/@vendure/core/src/api/middleware/validate-custom-fields-interceptor.ts:92:17)\n at async ValidateCustomFieldsInterceptor.intercept (/home/pieter/projects/ecommerce-engine/node_modules/@vendure/core/src/api/middleware/validate-custom-fields-interceptor.ts:62:33)", "message": "All text before the first colon: removed but after: replaced by a dot", "extensions": { "code": "USER_INPUT_ERROR" }, "code": "USER_INPUT_ERROR", "logLevel": 1 }, "extensions": { "code": "USER_INPUT_ERROR" } }], "data": null }
3. Expected error message should be: `All text before the first colon: removed but after: replaced by a dot` 4. FYI: the dev server outputs the message correctly: `[dev:server] warn 4/28/23, 7:25 AM - [Vendure Server] USER_INPUT_ERROR: All text before the first colon: removed but after: replaced by a dot`

Expected behavior
The server should return the unmodified version of the error message.

Environment (please complete the following information):

  • @vendure/core version: 1.9.5
  • Nodejs version: v16.19.0
  • Database (mysql/postgres etc): Postgres

Additional context
When throwing an exception in onTransitionStart when transitioning an order the same thing happens with the Error text propagated through the GraphQL API. It is stripped until the first ':' and subsequent colons are replaced with a dot ..

@seminarian seminarian added the type: bug 🐛 Something isn't working label Apr 28, 2023
@michaelbromley
Copy link
Member

This transformation of the error message is caused by the i18next lib we use to handle i18n on error messages.

Related:

We can solve this by turning off the namespaces feature - we don't use it anyway.

@seminarian
Copy link
Contributor Author

That was fast, thanks @michaelbromley !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants