Skip to content

Hex Errors

Hex.IntegerOutOfRangeError

Thrown when the provided integer is out of range, and cannot be represented as a hex value.

Examples

import { Hex } from 'ox'
 
Hex.fromNumber(420182738912731283712937129)
Hex.IntegerOutOfRangeError: Number \`4.2018273891273126e+26\` is not in safe unsigned integer range (`0` to `9007199254740991`)

Source: src/core/Hex.ts

Hex.InvalidHexBooleanError

Thrown when the provided hex value cannot be represented as a boolean.

Examples

import { Hex } from 'ox'
 
Hex.toBoolean('0xa')
Hex.InvalidHexBooleanError: Hex value `"0xa"` is not a valid boolean.
The hex value must be `"0x0"` (false) or `"0x1"` (true).

Source: src/core/Hex.ts

Hex.InvalidHexTypeError

Thrown when the provided value is not a valid hex type.

Examples

import { Hex } from 'ox'
 
Hex.assert(1)
Hex.InvalidHexTypeError: Value `1` of type `number` is an invalid hex type.

Source: src/core/Hex.ts

Hex.InvalidHexValueError

Thrown when the provided hex value is invalid.

Examples

import { Hex } from 'ox'
 
Hex.assert('0x0123456789abcdefg')
Hex.InvalidHexValueError: Value `0x0123456789abcdefg` is an invalid hex value.
Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).

Source: src/core/Hex.ts

Hex.InvalidLengthError

Thrown when the provided hex value is an odd length.

Examples

import { Bytes } from 'ox'
 
Bytes.fromHex('0xabcde')
Hex.InvalidLengthError: Hex value `"0xabcde"` is an odd length (5 nibbles).

Source: src/core/Hex.ts

Hex.SizeExceedsPaddingSizeError

Thrown when the size of the value exceeds the pad size.

Examples

import { Hex } from 'ox'
 
Hex.padLeft('0x1a4e12a45a21323123aaa87a897a897a898a6567a578a867a98778a667a85a875a87a6a787a65a675a6a9', 32)
Hex.SizeExceedsPaddingSizeError: Hex size (`43`) exceeds padding size (`32`).

Source: src/core/Hex.ts

Hex.SizeOverflowError

Thrown when the size of the value exceeds the expected max size.

Examples

import { Hex } from 'ox'
 
Hex.fromString('Hello World!', { size: 8 })
Hex.SizeOverflowError: Size cannot exceed `8` bytes. Given size: `12` bytes.

Source: src/core/Hex.ts

Hex.SliceOffsetOutOfBoundsError

Thrown when the slice offset exceeds the bounds of the value.

Examples

import { Hex } from 'ox'
 
Hex.slice('0x0123456789', 6)
Hex.SliceOffsetOutOfBoundsError: Slice starting at offset `6` is out-of-bounds (size: `5`).

Source: src/core/Hex.ts