node-slack-sdk icon indicating copy to clipboard operation
node-slack-sdk copied to clipboard

Main thread crashes due to unhandled error from @slack/web-api SDK

Open sergio-toro opened this issue 4 months ago • 2 comments

This error is the same as https://github.com/slackapi/node-slack-sdk/issues/1626 which was closed, but we are getting it in the last released version of the SDK

Packages:

Select all that apply:

  • [x] @slack/web-api
  • [ ] @slack/rtm-api
  • [ ] @slack/webhooks
  • [x] @slack/oauth
  • [ ] @slack/socket-mode
  • [ ] @slack/types
  • [ ] I don't know

Reproducible in:

The Slack SDK version

"slack/oauth": "^3.0.0",
"slack/web-api": "^7.0.2",

Node.js runtime version

v18.19.0

OS info

amazonlinux:2023.2.20231113.0

Steps to reproduce:

The app is running on long thread, sometimes the WebClient just crashes when doing a request and instead of rejecting the promise that is awaiting the response it bubbles up the error and kills the main thread

Expected result:

The request to Slack rejects the call due to a legit error (account_inactive) and the error can be matched.

try {
	const client = new WebClient()
	const { ok, user } = await client.users.lookupByEmail({
		token: botToken,
		email,
	});
} catch(error) {
	console.error("Slack request error", error);
}

Actual result:

// The error on the process uncaughtException listener
"code": "slack_webapi_platform_error",
"data": {
	"error": "account_inactive",
	"ok": false
}

// Additional stack trace
Error: An API error occurred: account_inactive
    at platformErrorFromResult (/srv/node_modules/@slack/web-api/dist/errors.js:62:33)
    at WebClient.<anonymous> (/srv/node_modules/@slack/web-api/dist/WebClient.js:198:60)
    at Generator.next (<anonymous>)
    at fulfilled (/srv/node_modules/@slack/web-api/dist/WebClient.js:28:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Code that represents what is happening

process.on("uncaughtException", (error, origin) => {
	console.error("Unhandled Slack error:", {
		error,
		origin,
	});
});

doSlackRequest("[email protected]", "valid-token")
	.then(/* ... */)
	.catch((error) => {
		console.error("Never gets executed", error);
	});

async function doSlackRequest(email, token) {
	try {
		const client = new WebClient()
		const { ok, user } = await client.users.lookupByEmail({
			token,
			email,
		});
		console.log("Slack request ok", user);
	} catch(error) {
		console.error("Slack request error", error);
	}
}

sergio-toro avatar Mar 07 '24 15:03 sergio-toro