feat: export error types via custom-error-creator (#52)#53
Conversation
Switch the error module to `custom-error-creator` (aligning with @comapeo/core) and add a dependency-light `./errors.js` public export so consumers can identify invalid-file errors. Every error class now exposes a stable static `.code` (e.g. `MISSING_CATEGORIES_ERROR`) and an HTTP `status`, while keeping the same `.name` values so existing name-based checks keep working. The `isParseError` / `isInvalidFileError` typeguards now match on `.code`. The new `./errors.js` entry re-exports the error classes and typeguards. Its import graph only pulls in `custom-error-creator` (zero deps) and pure constants — no yauzl, node streams, or valibot — so it is safe to import into a React Native bundle without the Reader/Writer. Errors with dynamic, multi-line messages build their message via small helper functions passed to the custom-message constructor form. Closes #52 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Investigation: pre-existing
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
…3.0)
Upgrade to custom-error-creator@1.3.0 and use its function-message param
to co-locate the dynamic message building inside the error definitions,
removing the separate message-builder helper functions. Drop the HTTP
`status` from every definition (now optional in 1.3.0) since these errors
don't map to HTTP statuses.
Call sites pass structured params directly again (e.g.
`new CategoryRefError({ missingRefs, property })`). SchemaError keeps
building its message at the call site so valibot stays out of the
frontend-safe errors module.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1.4.0 makes a defaulted function-message param optional in the
constructor while still allowing the params object to be passed, so
`new MissingCategoriesError()` works again without `({})`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…evel Move the errors module from src/lib/errors.js to src/errors.js (it's a public entry point, not an internal lib) and update all importers. Add two typeguards, both narrowing `err.code` to the matching union of codes: - `isKnownError(err)` — the error was thrown by this module. - `isValidationError(err)` — an expected validation error (bad input or invalid file): every known error except the programmer-error `AddAfterFinishError`. Lets consumers show a friendly message and skip error reporting (e.g. Sentry). A single KNOWN_ERRORS array drives both the runtime check and the KnownError / KnownErrorCode / ValidationError types, so adding an error keeps both in sync. Document the new exports in the README. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Closes #52.
What
Switches the error module to
custom-error-creator(the same library@comapeo/coreuses) and adds a dependency-light./errors.jspublic export so CoMapeo mobile can identify invalid-file errors crossing the nodejs-mobile IPC bridge — to show a friendly message and to avoid reporting expected user-input errors to Sentry.Changes
src/lib/errors.js— every error class is now created withcreateErrorClass(...). Each carries a stable static.code(e.g.MISSING_CATEGORIES_ERROR,INVALID_ZIP_FILE_ERROR). Codes are the screaming-snake form of the existing class names, so.nameis preserved and any existing name-based checks keep working.isParseError/isInvalidFileErrornow match on the stable.code. Dropped thenode:pathdependency.src/errors.js(new) — the public, frontend-safe entry. Re-exports the error classes and typeguards. Its import graph pulls in onlycustom-error-creator(zero deps) and pure constants — no yauzl, node streams, or valibot — so it is safe to import into a React Native bundle without the Reader/Writer.package.json— adds the./errors.jsexport entry and thecustom-error-creatordependency.tsconfig.npm.json— includessrc/errors.jssodist/errors.d.tsis emitted.CategoryRefError,InvalidCategorySelectionError,DuplicateTagsError,UnsupportedFileVersionError,MissingCategoriesError) usecustom-error-creator@1.3.0's typed function-message param, so the message building lives in the error definition and call sites pass structured params (new CategoryRefError({ missingRefs, property })).SchemaErrorkeeps building its message at the call site so valibot stays out of the frontend-safe module.No HTTP
statusis set on the errors (optional incustom-error-creator@1.3.0) since these don't map to HTTP statuses. Recognise errors by.code.Consumer usage
Verification
tsc -p tsconfig.jsonclean except one pre-existing, unrelatedschema.test-d.tserror (see comment below).eslintclean,npm run build:typesemitsdist/errors.d.ts.🤖 Generated with Claude Code