Skip to content

Release 0.1.1: clear errors and a minified package - #2

Merged
dopbase merged 8 commits into
mainfrom
release/0.1.1
Nov 14, 2026
Merged

dopbase merged 8 commits into
mainfrom
release/0.1.1

Conversation

@thomijasir

Copy link
Copy Markdown
Contributor

Summary

When load() failed, Node and Bun printed our own source code above the error, and the message often didn't say what went wrong. A bad certificate and a server that wasn't running both read "Couldn't reach Dopbase". This release fixes the errors and ships a minified package.

  • Errors point at the line in the app that called the SDK, not at dist/.
  • Schema errors list each failing key on its own line, then what to do. Values still never appear.
  • Network failures say what happened and how to fix it, with new codes: TLS_ERROR, CONNECTION_REFUSED, DNS_ERROR and CONNECTION_RESET.
  • Printed errors no longer show status: undefined and requestId: undefined, or list issues twice.
  • The npm package is minified and ships no source maps. The old maps embedded every TypeScript file.
  • Publishing moves into release.yml, which runs on version tags. NOTICE ships in the package.

Breaking change

Refused connections, TLS failures, DNS failures and resets used to have code: 'NETWORK_ERROR'. They now use the four codes above. They're all still DopbaseNetworkError, so retries and the offline fallback work the same way. Code that matches error.code === 'NETWORK_ERROR' should check instanceof DopbaseNetworkError instead. Any other network failure keeps NETWORK_ERROR.

Before and after

Real output from the same app and fake server, with 0.1.0 and with this branch. Paths are shortened to /app.

Schema error, Node 26

Before:

file:///app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:1071
        const error = new DopbaseValidationError(
                      ^

DopbaseValidationError: Secrets in development don't match the schema: APP_SECRET: Invalid URL; DB_HOST: Invalid input: expected number, received NaN.
    at #apply (file:///app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:1071:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async #firstLoad (file:///app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:966:9)
    at async DopbaseSDK.load (file:///app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:842:7)
    at async file:///app/app.mjs:6:1 {
  code: 'SCHEMA_INVALID',
  status: undefined,
  requestId: undefined,
  issues: [
    { key: 'APP_SECRET', message: 'Invalid URL' },
    {
      key: 'DB_HOST',
      message: 'Invalid input: expected number, received NaN'
    }
  ]
}

After:

node:internal/process/task_queues:104
    runMicrotasks();
    ^

DopbaseValidationError: 2 secrets in "development" don't match your schema:
  - APP_SECRET: Invalid URL
  - DB_HOST: Invalid input: expected number, received NaN
Fix them in Dopbase, or change the schema.
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async file:///app/app.mjs:6:1 {
  code: 'SCHEMA_INVALID'
}

Self-signed certificate, Bun 1.4

Before:

575 |             code: "TIMEOUT",
576 |             cause: error
577 |           }
578 |         );
579 |       }
580 |       throw new DopbaseNetworkError(`Couldn't reach Dopbase at ${baseUrl}.`, {
                  ^
DopbaseNetworkError: Couldn't reach Dopbase at https://localhost:8842.
    status: undefined,
 requestId: undefined,
      code: "NETWORK_ERROR"

      at #attempt (/app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:580:13)
      at async fetch (/app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:540:27)
      at async #firstLoad (/app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:958:38)

558 |     if (etag) headers["If-None-Match"] = etag;
559 |     const timeout = timeoutSignal(timeoutMs);
560 |     const fetchImpl = this.#options.fetch ?? globalThis.fetch;
561 |     let response;
562 |     try {
563 |       response = await fetchImpl(endpoint, {
                             ^
TypeError: self signed certificate
  path: "https://localhost:8842/api/v1/runtime/secrets",
 errno: 0,
  code: "DEPTH_ZERO_SELF_SIGNED_CERT"

      at async #attempt (/app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:563:24)
      at async fetch (/app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:540:27)

After:

6 | async function start() {
7 |   const env = new DopbaseSDK({ host: process.env.HOST, ... });
8 |   await env.load();
                ^
DopbaseNetworkError: Couldn't verify the TLS certificate of https://localhost:8842 (DEPTH_ZERO_SELF_SIGNED_CERT).
For local development, use http://localhost:8842, or trust the certificate with NODE_EXTRA_CA_CERTS.
 code: "TLS_ERROR"

      at async start (/app/server-app.mjs:8:13)

error: self signed certificate
 code: "DEPTH_ZERO_SELF_SIGNED_CERT"

Server not running, Node 26

Before (41 lines, shortened):

file:///app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:580
      throw new DopbaseNetworkError(`Couldn't reach Dopbase at ${baseUrl}.`, {
            ^

DopbaseNetworkError: Couldn't reach Dopbase at http://localhost:8849.
    at #attempt (file:///app/node_modules/@dopbase/sdk/dist/chunk-ZVKYVQHE.js:580:13)
    ... 4 more SDK frames
  code: 'NETWORK_ERROR',
  status: undefined,
  requestId: undefined,
  [cause]: [TypeError: fetch failed] {
    [cause]: AggregateError [ECONNREFUSED]:
        ... 25 lines: one ECONNREFUSED error for ::1 and one for 127.0.0.1

After:

node:internal/process/task_queues:104
    runMicrotasks();
    ^

DopbaseNetworkError: Nothing is answering at http://localhost:8849.
Check that the Dopbase server is running and that DOPBASE_HOST is right.
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async file:///app/app.mjs:6:1 {
  code: 'CONNECTION_REFUSED',
  [cause]: [AggregateError: ECONNREFUSED] { code: 'ECONNREFUSED' }
}

Bad option, Node 26

Before, the arrow pointed at normalizeHost inside dist/chunk-ZVKYVQHE.js:239. After:

file:///app/server-app.mjs:7
  const env = new DopbaseSDK({ host: process.env.HOST, ... });
              ^

DopbaseConfigError: Plain http:// is only allowed for localhost. Use https:// for this host.
    at start (file:///app/server-app.mjs:7:15)
    ...
  code: 'HOST_INSECURE'
}

The package (npm pack --dry-run)

0.1.0 0.1.1
Packed 150.0 kB about 53 kB
Unpacked 571.5 kB about 159 kB
Files 40 26
TypeScript source inside yes, in every .js.map no

How it works

  • Stack. The constructor, load, refresh, get, require, has, getAll and onChange call Error.captureStackTrace(error, method) before rethrowing a DopbaseError, so the first frame is the app's call. Errors passed to onError have no app call, so they carry no frames. Overwriting error.stack as a string doesn't work: both runtimes still print the line where the error was created.
  • Network reasons. reasonOf() in transport.ts finds the runtime's code: Node keeps it in cause, sometimes two levels down, and Bun puts it on the error itself. Deno sets no code, so its message text is the fallback. The new cause is a small error with that message, name and code, and no stack.
  • Build. tsup builds with minify, keepNames and no source maps. Without keepNames, Node printed m [DopbaseValidationError]. scripts/check-dist.mjs runs after every build and fails on a source map, an unminified file, or an error class that lost its name in ESM or CJS.

Testing

  • npm run lint and npm run typecheck: clean.
  • npm test: 165 passed. New tests cover:
    • the schema message, singular and plural
    • stack trimming for every public method and the constructor
    • which fields a printed error shows
    • each fetch failure shape from Node, Bun and Deno
    • keeping the cause's name, including TimeoutError
  • SMOKE_SUPABASE=1 npm run test:runtimes: Node ESM, Node CJS, --import register, Bun, Deno, Cloudflare workerd, Vercel Edge and Supabase all pass. The new scripts/smoke/flows.mjs runs on all of them except Node CJS and --import register, and checks error codes, a 401, the schema message and the offline fallback. With the 0.1.0 build swapped in, it fails on every runtime that runs it.
  • Old vs new: I ran 46 flows on both builds in Node, Bun, Deno, workerd and Vercel Edge and compared the output field by field. 26 are identical on every runtime: reads, onChange, refresh(), schema results, every HTTP error, retries, the offline fallback, inject, and a real load. The other 20 differ only in message text, codes, the slimmer cause, and the removed empty fields.
  • By hand: 16 failure cases in Node 26 and Bun 1.4 against the built package. None printed SDK source or an empty field.
  • Each feature commit passes typecheck and the tests on its own.

Known limits

  • In Node, an error thrown after an await still has Node's own runMicrotasks() line on top. That's Node's code, and a library can't remove it.
  • Cloudflare workerd only reports "Network connection lost" for a refused connection, so it stays NETWORK_ERROR, as in 0.1.0.
  • A user's bug report now shows minified frames. The error code and message, plus DEBUG=dopbase logs, carry what we need.

Releasing

After merge, tag 0.1.1 on main and push the tag. release.yml checks that the tag, package.json and CHANGELOG.md agree, then publishes to npm and opens the GitHub release.

Publishing moves out of ci.yml into release.yml. A version tag now runs
the CI jobs through workflow_call, then checks that the tag matches the
package.json version, points at a commit on main, and has a CHANGELOG
section before it publishes.

Prereleases such as 0.2.0-beta.1 go out under their own npm dist-tag,
so the latest stable version stays the default install. After npm, the
workflow opens a GitHub release with that version's changelog entry.
A version already on npm is skipped instead of failing the run.
Apache-2.0 expects the NOTICE file to travel with the code, so it now
ships in the npm package next to LICENSE.
Node and Bun print the source line of an error's first stack frame. For
SDK errors that frame was always inside dist/, so users saw SDK code
above every message. The constructor, load, refresh, get, require, has,
getAll and onChange now restart the stack at the app's own call, and
errors passed to onError carry no frames at all.

Schema errors list one key per line under a count, followed by what to
do. Values still never appear.

status and requestId are only set when the server answered, so printed
errors no longer show "status: undefined". issues is frozen and no
longer enumerable, since the message already lists it.
Every fetch failure used to read "Couldn't reach Dopbase", with the
real reason buried one or two levels down in cause. The SDK now reads
the runtime's error code (Node keeps it in cause, Bun on the error) and
falls back to the message text for Deno, which sets no code.

TLS, refused, DNS and reset failures get their own code and a second
line that says what to fix. A local TLS failure suggests http:// or
NODE_EXTRA_CA_CERTS. All of them are still DopbaseNetworkError, so
retries and the offline fallback behave as before.

cause is now a small error with the runtime's message, name and code
but no stack, so Node no longer prints the whole AggregateError chain
and Bun no longer prints fetch internals.

BREAKING CHANGE: refused connections, TLS failures, DNS failures and
resets now use CONNECTION_REFUSED, TLS_ERROR, DNS_ERROR and
CONNECTION_RESET instead of NETWORK_ERROR. Check for
DopbaseNetworkError instead of matching the NETWORK_ERROR code.
The published maps embedded every TypeScript source file, and the
readable dist/ let runtimes print SDK code above errors. The build is
now minified with no source maps. keepNames stays on, or Node prints a
renamed class next to the error name (m [DopbaseValidationError]).

scripts/check-dist.mjs runs after every build and fails if dist/ holds
a source map, isn't minified, or an error class lost its name in the
ESM or CJS build. The packed package drops from 150 kB to about 53 kB.
The smoke checks only loaded one value. flows.mjs now runs on Node,
Bun, Deno, Cloudflare workerd, Vercel Edge and Supabase, and checks
the network error codes for each runtime's error shape, a 401, the
schema message, and the offline fallback from a shared store.

On Node, Bun and Deno it also checks that no error the app sees has a
stack frame inside dist/. Run against the 0.1.0 build, these checks
fail on every runtime that runs them.
Lists each DopbaseNetworkError code with what it means, notes that all
but ABORTED are retried and can use the stored copy, and explains how
to reach a local server with a self-signed certificate.
Adds the 0.1.1 entry and bumps the version in package.json and
package-lock.json.
@sonarqubecloud

Copy link
Copy Markdown

@dopbase dopbase left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

@dopbase
dopbase merged commit 3b5d00f into main Nov 14, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants