unacy / ConversionError
Class: ConversionError
Defined in: packages/core/src/errors.ts:151
Error thrown when a conversion cannot be performed.
Remarks
ConversionError is the most common error consumers encounter. It is thrown when no direct edge and no BFS-discoverable path exists between two units, or when allow() is called for a pair with no reachable path.
Inspect e.from and e.to to determine which units are missing a path, then register the required converter with registry.register(from, to, fn).
Example
try {
registry.convert(temp, 'Celsius').to('Miles'); // no path
} catch (e) {
if (e instanceof ConversionError) {
console.error(`No path from ${String(e.from)} to ${String(e.to)}`);
}
}Pitfalls
NEVER call registry.convert(value, fromUnit).to(toUnit) without handling ConversionError — the path may not exist even if both units are registered.
NEVER confuse a missing converter with a wrong-direction converter — if A → B is registered but B → A is not, converting B to A throws ConversionError, not a type error.
Extends
Constructors
Constructor
new ConversionError(
from,
to,
reason?): ConversionError;Defined in: packages/core/src/errors.ts:155
Parameters
| Parameter | Type |
|---|---|
from | PropertyKey |
to | PropertyKey |
reason? | string |
Returns
ConversionError
Overrides
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
cause? | public | unknown | UnacyError.cause | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24 |
from | readonly | PropertyKey | - | packages/core/src/errors.ts:152 |
message | public | string | UnacyError.message | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075 |
name | public | string | UnacyError.name | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074 |
stack? | public | string | UnacyError.stack | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076 |
to | readonly | PropertyKey | - | packages/core/src/errors.ts:153 |