saleor / apps

A central space for Saleor Apps, integrations, and the App Store 🚀
https://apps.saleor.io
Other
108 stars 298 forks source link

[emails & messages] tRPC internal server error while saving configuration #1135

Open madmonkeyworks opened 9 months ago

madmonkeyworks commented 9 months ago

Hi there,

I am self-hosting the Emails & Messages Saleor app and testing it in Saleor dev sandbox. When saving email provider configuration, an internal server error pops up. This error appears only in Saleor dev sandbox. Local deployment on saleor-platform works well.

Setup

Steps to reproduce

  1. Self-host Emails & Messages app (in my case it's AWS Amplify)
  2. Go to app configuration
  3. Enter details for "SMTP server" > hit save [configuration successfully saved]
  4. Enter details for "Sender" > hit save [saving configuration fails with error 500]

Error

"name": "tRPC error",
"err": {
        "type": "TRPCError",
        "message": "Internal server error",
        "stack": "TRPCError: Internal server error\n    at throwTrpcErrorFromConfigurationServiceError (/tmp/app/.next/server/pages/api/trpc/[trpc].js:918:11)\n    at /tmp/app/.next/server/pages/api/trpc/[trpc].js:1101:20\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async resolveMiddleware (file:///var/task/node_modules/@trpc/server/dist/index.mjs:420:30)\n    at async callRecursive (file:///var/task/node_modules/@trpc/server/dist/index.mjs:456:32)\n    at async callRecursive (file:///var/task/node_modules/@trpc/server/dist/index.mjs:456:32)\n    at async /tmp/app/.next/server/pages/api/trpc/[trpc].js:1230:20\n    at async callRecursive (file:///var/task/node_modules/@trpc/server/dist/index.mjs:456:32)\n    at async callRecursive (file:///var/task/node_modules/@trpc/server/dist/index.mjs:456:32)\n    at async callRecursive (file:///var/task/node_modules/@trpc/server/dist/index.mjs:456:32)",
        "code": "INTERNAL_SERVER_ERROR",
        "name": "TRPCError"
    },
"msg": "smtpConfiguration.updateSender returned error:"

As I mentioned, all works well in local development, i.e. saleor-platform + app via localhost, with both custom APL and file APL. It's only the Saleor dev sandbox and app deployed on AWS which trows the error.

Can you help?

lkostrowski commented 9 months ago

Please set APP_LOG_LEVEL=trace and check if you have some logs in the console

madmonkeyworks commented 9 months ago

Thanks for the tip @lkostrowski. Below is the trace log. All looks ok to me, until the crash on "smtpConfiguration.updateSender". Any idea what's going on?

{
    "level": 20,
    "time": 1702414790130,
    "pid": 52,
    "hostname": "169.254.83.125",
    "name": "AwsGraphQLAPL",
    "msg": "AuthData successfully retrieved."
}
{
    "level": 20,
    "time": 1702414790130,
    "pid": 52,
    "hostname": "169.254.83.125",
    "permissions": [
        "MANAGE_APPS"
    ],
    "msg": "Calling validateClientToken middleware with permissions required"
}
{
    "level": 20,
    "time": 1702414790130,
    "pid": 52,
    "hostname": "169.254.83.125",
    "msg": "trying to verify JWT token from frontend"
}
{
    "level": 20,
    "time": 1702414790130,
    "pid": 52,
    "hostname": "169.254.83.125",
    "token": "[Redacted]"
}
{
    "level": 20,
    "time": 1702414790389,
    "pid": 52,
    "hostname": "169.254.83.125",
    "saleorApiUrl": "https://santafoodev.eu.saleor.cloud/graphql/",
    "id": "1702414701563e9cxw",
    "senderEmail": "santafoo-dev-admin@aarini.com",
    "senderName": "Santafoo DEV",
    "msg": "smtpConfigurationRouter.updateSender called"
}
{
    "level": 20,
    "time": 1702414790389,
    "pid": 52,
    "hostname": "169.254.83.125",
    "name": "SmtpConfigurationService",
    "msg": "Update configuration"
}
{
    "level": 20,
    "time": 1702414790389,
    "pid": 52,
    "hostname": "169.254.83.125",
    "name": "SmtpConfigurationService",
    "msg": "Get configuration"
}
{
    "level": 20,
    "time": 1702414790389,
    "pid": 52,
    "hostname": "169.254.83.125",
    "name": "SmtpConfigurationService",
    "msg": "Get configuration root"
}
{
    "level": 20,
    "time": 1702414790389,
    "pid": 52,
    "hostname": "169.254.83.125",
    "name": "SmtpConfigurationService",
    "msg": "Fetch configuration from Saleor API"
}
{
    "level": 20,
    "time": 1702414790389,
    "pid": 52,
    "hostname": "169.254.83.125",
    "name": "SmtpPrivateMetadataManager",
    "msg": "Fetching config in the current version"
}
{
    "level": 20,
    "time": 1702414790732,
    "pid": 52,
    "hostname": "169.254.83.125",
    "name": "SmtpConfigurationService",
    "msg": "Get configuration root"
}
{
    "level": 20,
    "time": 1702414790732,
    "pid": 52,
    "hostname": "169.254.83.125",
    "name": "SmtpConfigurationService",
    "msg": "Using cached configuration"
}
{
    "level": 50,
    "time": 1702414790733,
    "pid": 52,
    "hostname": "169.254.83.125",
    "name": "tRPC error",
    "err": {
        "type": "TRPCError",
        "message": "Internal server error",
        "stack": "TRPCError: Internal server error\n    at throwTrpcErrorFromConfigurationServiceError (/tmp/app/.next/server/pages/api/trpc/[trpc].js:916:11)\n    at /tmp/app/.next/server/pages/api/trpc/[trpc].js:1096:20\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async resolveMiddleware (file:///var/task/node_modules/@trpc/server/dist/index.mjs:420:30)\n    at async callRecursive (file:///var/task/node_modules/@trpc/server/dist/index.mjs:456:32)\n    at async callRecursive (file:///var/task/node_modules/@trpc/server/dist/index.mjs:456:32)\n    at async /tmp/app/.next/server/pages/api/trpc/[trpc].js:1225:20\n    at async callRecursive (file:///var/task/node_modules/@trpc/server/dist/index.mjs:456:32)\n    at async callRecursive (file:///var/task/node_modules/@trpc/server/dist/index.mjs:456:32)\n    at async callRecursive (file:///var/task/node_modules/@trpc/server/dist/index.mjs:456:32)",
        "code": "INTERNAL_SERVER_ERROR",
        "name": "TRPCError"
    },
    "msg": "smtpConfiguration.updateSender returned error:"
}
lkostrowski commented 9 months ago

At the moment only I can help is that you check the error source (updateSender procedure) and try to log the error. Looks like its missing in the logs. I'd be great if you open the PR if you have the fix