Skip to content

unacy / MaxDepthError

Class: MaxDepthError

Defined in: packages/core/src/errors.ts:103

Error thrown when BFS path-finding exceeds the maximum conversion depth.

Remarks

The maximum depth is currently fixed at 5 hops. This prevents the BFS from exploring excessively large graphs and guards against near-cycles (long paths that would be impractical for production use anyway).

If you hit this error, consider:

  1. Using allow(A, Z) to cache the composed path once found, avoiding repeated BFS traversal.
  2. Splitting a long dimension chain into domain-specific sub-registries.
  3. Registering a direct edge for the problematic pair.

Example

typescript
try {
  registry.getConverter('A', 'F'); // requires 6-hop path
} catch (e) {
  if (e instanceof MaxDepthError) {
    console.error(`Path A→F exceeds max depth of ${e.maxDepth}`);
  }
}

Pitfalls

NEVER design a conversion graph that relies on paths longer than 5 hops — MaxDepthError is thrown at runtime and cannot be caught as a type error. Register intermediate direct edges or use allow() to cap the chain.

Extends

Constructors

Constructor

ts
new MaxDepthError(
   from, 
   to, 
   maxDepth): MaxDepthError;

Defined in: packages/core/src/errors.ts:108

Parameters

ParameterType
fromPropertyKey
toPropertyKey
maxDepthnumber

Returns

MaxDepthError

Overrides

UnacyError.constructor

Properties

PropertyModifierTypeInherited fromDefined in
cause?publicunknownUnacyError.causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
fromreadonlyPropertyKey-packages/core/src/errors.ts:104
maxDepthreadonlynumber-packages/core/src/errors.ts:106
messagepublicstringUnacyError.messagenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075
namepublicstringUnacyError.namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
stack?publicstringUnacyError.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
toreadonlyPropertyKey-packages/core/src/errors.ts:105

Released under the MIT License.