From a252e13ea140483efca8907ea16eb6e2b202a4c9 Mon Sep 17 00:00:00 2001 From: Stefan Andres Charsley Date: Fri, 29 Jul 2022 02:48:38 +0000 Subject: [PATCH] fix: remove catch from handler in transaction --- .devcontainer/Dockerfile | 22 ++++++++++++++++++++ .devcontainer/devcontainer.json | 37 +++++++++++++++++++++++++++++++++ src/index.js | 9 ++------ 3 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..47eb6801 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,22 @@ +# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster +ARG VARIANT=16-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT} + +ENV DENO_INSTALL=/deno +RUN mkdir -p /deno \ + && curl -fsSL https://deno.land/x/install/install.sh | sh \ + && chown -R node /deno + +ENV PATH=${DENO_INSTALL}/bin:${PATH} \ + DENO_DIR=${DENO_INSTALL}/.cache/deno + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# ARG EXTRA_NODE_VERSION=10 +# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" + +# [Optional] Uncomment if you want to install more global node packages +# RUN su node -c "npm install -g " diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..c5466490 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,37 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/typescript-node +{ + "name": "Node.js & TypeScript", + "build": { + "dockerfile": "Dockerfile", + // Update 'VARIANT' to pick a Node version: 18, 16, 14. + // Append -bullseye or -buster to pin to an OS version. + // Use -bullseye variants on local on arm64/Apple Silicon. + "args": { + "VARIANT": "18-bullseye" + } + }, + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "dbaeumer.vscode-eslint" + ] + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "npm install", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "node", + "features": { + "docker-from-docker": "latest" + } +} diff --git a/src/index.js b/src/index.js index 5998d449..3af7cfda 100644 --- a/src/index.js +++ b/src/index.js @@ -209,8 +209,7 @@ function Postgres(a, b) { async function scope(c, fn, name) { const sql = Sql(handler) sql.savepoint = savepoint - let uncaughtError - , result + let result name && await sql`savepoint ${ sql(name) }` try { @@ -218,15 +217,12 @@ function Postgres(a, b) { const x = fn(sql) Promise.resolve(Array.isArray(x) ? Promise.all(x) : x).then(resolve, reject) }) - - if (uncaughtError) - throw uncaughtError } catch (e) { await (name ? sql`rollback to ${ sql(name) }` : sql`rollback` ) - throw e instanceof PostgresError && e.code === '25P02' && uncaughtError || e + throw e } !name && await sql`commit` @@ -241,7 +237,6 @@ function Postgres(a, b) { } function handler(q) { - q.catch(e => uncaughtError || (uncaughtError = e)) c.queue === full ? queries.push(q) : c.execute(q) || move(c, full)