Skip to content

fix: normalize non-Error rejections in asyncHandler, add tests, docum… - #1567

Merged
ogazboiz merged 2 commits into
LabsCrypt:mainfrom
ExcelDsigN-tech:feat/async-error-normalization-test-coverage-docs
Jul 29, 2026
Merged

fix: normalize non-Error rejections in asyncHandler, add tests, docum…#1567
ogazboiz merged 2 commits into
LabsCrypt:mainfrom
ExcelDsigN-tech:feat/async-error-normalization-test-coverage-docs

Conversation

@ExcelDsigN-tech

Copy link
Copy Markdown

Closes #1548, Closes #1549, Closes #1550, Closes #1551

Overview

This PR addresses backend rejection normalization, query helper test coverage gaps, Soroban SDK version documentation alignment, and cross-layer PII privacy documentation across the repository stack.

Specifically, it ensures non-Error promise rejections in Express route handlers are converted to valid Error instances for proper stack trace logging, completes test coverage for SQL query generation helpers, documents Soroban SDK toolchain dependencies, and details PII handling across frontend masking and backend encryption layers in the security model.

Feature Summary

  • Async Handler Rejection Normalization: Updated asyncHandler.ts to wrap non-Error rejections (e.g., strings, plain objects, or undefined) into proper Error instances before delegating to next(), ensuring logger stack trace integrity.
  • Comprehensive SQL Query Helper Tests: Expanded queryHelpers.test.ts to achieve full test coverage for all exported functions in queryHelpers.ts, covering empty filters, edge cases, and SQL injection / parameterization safety.
  • Toolchain Version Documentation: Updated contracts/README.md to document minimum required soroban-sdk and soroban-cli versions, adding sync comments in contracts/Cargo.toml.
  • PII Security Architecture Documentation: Added a comprehensive matrix in docs/SECURITY-MODEL.md documenting field-level PII policies across frontend display masking (piiMask.ts) and backend at-rest encryption (piiCrypto.ts).

Technical Implementation

  • Rejection Normalization (backend/src/utils/asyncHandler.ts): Updated the .catch() handler within asyncHandler to inspect the rejected reason. If !(err instanceof Error), converted it via new Error(typeof err === 'string' ? err : JSON.stringify(err)) before forwarding to next(err).
  • Query Helper Verification (backend/src/utils/tests/queryHelpers.test.ts): Added unit test cases for all exported query builders, verifying correct parameter positioning, handling of empty/null filter objects, and SQL string escaping safety.
  • Toolchain Coupling (contracts/README.md, contracts/Cargo.toml): Documented explicit version parity requirements between soroban-sdk and soroban-cli in the setup guide and linked Cargo.toml dependencies with maintainer inline comments.
  • Security Model Spec (docs/SECURITY-MODEL.md): Mapped out PII field classifications (e.g., email, phone, SSN/tax ID, physical address) detailing frontend display masking rules (piiMask.ts) and backend encryption at rest (piiCrypto.ts).

Test Coverage

  • Async Handler Tests: Added unit tests verifying that thrown strings, numbers, and undefined values produce valid Error instances containing usable stack traces when passed to the error handler.
  • Query Helpers Tests: Audited all exported functions in queryHelpers.ts to guarantee 100% test coverage across standard filtering and edge case scenarios.
  • CI & Linter Verification: All unit tests, TypeScript type checks, and linter runs executed successfully across backend, frontend, and smart contract workspace modules.

Checklists

  • Non-Error rejections normalized to Error instances in asyncHandler.ts
  • Unit test added for asyncHandler.ts verifying thrown string conversion and stack trace generation
  • Full test coverage added for all functions in queryHelpers.ts
  • Minimum soroban-sdk and soroban-cli versions documented in contracts/README.md and synced with Cargo.toml
  • PII field handling matrix added to docs/SECURITY-MODEL.md detailing frontend masking and backend encryption

ExcelDsigN-tech added 2 commits July 29, 2026 05:35
…ent SDK version and PII inventory

- asyncHandler.ts normalizes non-Error rejections (string, undefined) into Error with cause before delegating to errorHandler
- New test file covers Error passthrough, string normalization, undefined normalization
- contracts/README.md adds soroban-sdk 22.0.0 version table; Cargo.toml gets coupling comment
- docs/SECURITY-MODEL.md adds PII field inventory covering email/phone/name/address across frontend mask and backend encrypt layers
- queryHelpers audit: single export parseCappedLimit has full coverage (8 tests, all edge cases)
@ogazboiz
ogazboiz merged commit 803c174 into LabsCrypt:main Jul 29, 2026
8 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment