Skip to content

unacy / CycleError

Class: CycleError

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

Error thrown when a cycle is detected during BFS path-finding.

Remarks

This error is thrown by findShortestPath when from === to (a unit being converted to itself). The registry's getConverter method re-throws CycleError rather than silently returning undefined.

Example

typescript
try {
  registry.getConverter('Celsius', 'Celsius'); // same unit
} catch (e) {
  if (e instanceof CycleError) {
    console.error('Cycle in path:', e.path.join(' → '));
  }
}

Pitfalls

NEVER call registry.convert(value, 'X').to('X') — converting a unit to itself triggers cycle detection and throws CycleError at runtime.

Extends

Constructors

Constructor

ts
new CycleError(path): CycleError;

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

Parameters

ParameterType
pathPropertyKey[]

Returns

CycleError

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
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
pathreadonlyPropertyKey[]-packages/core/src/errors.ts:61
stack?publicstringUnacyError.stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076

Released under the MIT License.