Skip to content

Commit

Permalink
log error stack
Browse files Browse the repository at this point in the history
  • Loading branch information
kane50613 committed Mar 4, 2024
1 parent 4d8189e commit 528f1f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redis-on-workers",
"version": "0.2.6",
"version": "0.2.7",
"description": "Connect to your Redis server using cloudflare:sockets",
"scripts": {
"build": "tsup",
Expand Down
21 changes: 20 additions & 1 deletion src/create-redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export function createRedis(options: CreateRedisOptions) {
async function raw(cmd: string, ...args: (string | number | Buffer)[]) {
const connect = await getConnectFn(options.connectFn);

options.logger?.("Connecting to", hostname, portNumber.toString());

const socket = connect(
{
hostname,
Expand Down Expand Up @@ -81,7 +83,15 @@ export function createRedis(options: CreateRedisOptions) {
}

startListener()
.catch(console.error)
.catch((e) => {
options.logger?.(
"Error sending command",
e.message,
e.stack ?? "No stack",
);

throw e;
})
.finally(async () => {
options.logger?.("Listener closed");
await closeSocket();
Expand Down Expand Up @@ -125,6 +135,15 @@ export function createRedis(options: CreateRedisOptions) {

try {
return await internalSend(commands).then((reply) => reply.at(-1) ?? null);
} catch (e) {
if (!(e instanceof Error)) throw e;

options.logger?.(
"Error sending command",
e.message,
e.stack ?? "No stack",
);
throw e;
} finally {
options.logger?.("Closing socket");
await closeSocket();
Expand Down

0 comments on commit 528f1f7

Please sign in to comment.