Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/easy-hands-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solana/errors': minor
---

Add 13 new error codes in the `[8090000, 8090999]` range for the upcoming `@solana/fixed-points` package: `INVALID_TOTAL_BITS`, `INVALID_FRACTIONAL_BITS`, `INVALID_DECIMALS`, `FRACTIONAL_BITS_EXCEED_TOTAL_BITS`, `VALUE_OUT_OF_RANGE`, `INVALID_STRING`, `INVALID_ZERO_DENOMINATOR_RATIO`, `ARITHMETIC_OVERFLOW`, `SHAPE_MISMATCH`, `DIVISION_BY_ZERO`, `STRICT_MODE_PRECISION_LOSS`, `MALFORMED_RAW_VALUE`, and `TOTAL_BITS_NOT_BYTE_ALIGNED`.
29 changes: 29 additions & 0 deletions packages/errors/src/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,22 @@ export const SOLANA_ERROR__CODECS__EXPECTED_DECODER_TO_CONSUME_ENTIRE_BYTE_ARRAY
export const SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_VALUE = 8078024;
export const SOLANA_ERROR__CODECS__INVALID_PATTERN_MATCH_BYTES = 8078025;

// Fixed-point-related errors.
// Reserve error codes in the range [8090000-8090999].
export const SOLANA_ERROR__FIXED_POINTS__INVALID_TOTAL_BITS = 8090000;
export const SOLANA_ERROR__FIXED_POINTS__INVALID_FRACTIONAL_BITS = 8090001;
export const SOLANA_ERROR__FIXED_POINTS__INVALID_DECIMALS = 8090002;
export const SOLANA_ERROR__FIXED_POINTS__FRACTIONAL_BITS_EXCEED_TOTAL_BITS = 8090003;
export const SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE = 8090004;
export const SOLANA_ERROR__FIXED_POINTS__INVALID_STRING = 8090005;
export const SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO = 8090006;
export const SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW = 8090007;
export const SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH = 8090008;
export const SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO = 8090009;
export const SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS = 8090010;
export const SOLANA_ERROR__FIXED_POINTS__MALFORMED_RAW_VALUE = 8090011;
export const SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED = 8090012;

// RPC-related errors.
// Reserve error codes in the range [8100000-8100999].
export const SOLANA_ERROR__RPC__INTEGER_OVERFLOW = 8100000;
Expand Down Expand Up @@ -451,6 +467,19 @@ export type SolanaErrorCode =
| typeof SOLANA_ERROR__CRYPTO__RANDOM_VALUES_FUNCTION_UNIMPLEMENTED
| typeof SOLANA_ERROR__FAILED_TO_SEND_TRANSACTION
| typeof SOLANA_ERROR__FAILED_TO_SEND_TRANSACTIONS
| typeof SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW
| typeof SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO
| typeof SOLANA_ERROR__FIXED_POINTS__FRACTIONAL_BITS_EXCEED_TOTAL_BITS
| typeof SOLANA_ERROR__FIXED_POINTS__INVALID_DECIMALS
| typeof SOLANA_ERROR__FIXED_POINTS__INVALID_FRACTIONAL_BITS
| typeof SOLANA_ERROR__FIXED_POINTS__INVALID_STRING
| typeof SOLANA_ERROR__FIXED_POINTS__INVALID_TOTAL_BITS
| typeof SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO
| typeof SOLANA_ERROR__FIXED_POINTS__MALFORMED_RAW_VALUE
| typeof SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH
| typeof SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS
| typeof SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED
| typeof SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE
| typeof SOLANA_ERROR__FS__UNSUPPORTED_ENVIRONMENT
| typeof SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS
| typeof SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA
Expand Down
83 changes: 83 additions & 0 deletions packages/errors/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ import {
SOLANA_ERROR__CODECS__UNION_VARIANT_OUT_OF_RANGE,
SOLANA_ERROR__FAILED_TO_SEND_TRANSACTION,
SOLANA_ERROR__FAILED_TO_SEND_TRANSACTIONS,
SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW,
SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO,
SOLANA_ERROR__FIXED_POINTS__FRACTIONAL_BITS_EXCEED_TOTAL_BITS,
SOLANA_ERROR__FIXED_POINTS__INVALID_DECIMALS,
SOLANA_ERROR__FIXED_POINTS__INVALID_FRACTIONAL_BITS,
SOLANA_ERROR__FIXED_POINTS__INVALID_STRING,
SOLANA_ERROR__FIXED_POINTS__INVALID_TOTAL_BITS,
SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO,
SOLANA_ERROR__FIXED_POINTS__MALFORMED_RAW_VALUE,
SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH,
SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS,
SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED,
SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE,
SOLANA_ERROR__FS__UNSUPPORTED_ENVIRONMENT,
SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,
SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,
Expand Down Expand Up @@ -461,6 +474,76 @@ export type SolanaErrorContext = ReadonlyContextValue<
}>;
transactionPlanResult: unknown;
};
[SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW]: {
kind: string;
max: bigint;
min: bigint;
operation: string;
result: bigint;
signedness: string;
totalBits: number;
};
[SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO]: {
kind: string;
signedness: string;
totalBits: number;
};
[SOLANA_ERROR__FIXED_POINTS__FRACTIONAL_BITS_EXCEED_TOTAL_BITS]: {
fractionalBits: number;
totalBits: number;
};
[SOLANA_ERROR__FIXED_POINTS__INVALID_DECIMALS]: {
decimals: unknown;
};
[SOLANA_ERROR__FIXED_POINTS__INVALID_FRACTIONAL_BITS]: {
fractionalBits: unknown;
};
[SOLANA_ERROR__FIXED_POINTS__INVALID_STRING]: {
input: string;
kind: string;
};
[SOLANA_ERROR__FIXED_POINTS__INVALID_TOTAL_BITS]: {
kind: string;
totalBits: unknown;
};
[SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO]: {
denominator: bigint;
kind: string;
numerator: bigint;
};
[SOLANA_ERROR__FIXED_POINTS__MALFORMED_RAW_VALUE]: {
kind: string;
raw: unknown;
};
[SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH]: {
actualKind: string;
actualScale: number;
actualScaleLabel: string;
actualSignedness: string;
actualTotalBits: number;
expectedKind: string;
expectedScale: number;
expectedScaleLabel: string;
expectedSignedness: string;
expectedTotalBits: number;
operation: string;
};
[SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS]: {
kind: string;
operation: string;
};
[SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED]: {
kind: string;
totalBits: number;
};
[SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE]: {
kind: string;
max: bigint;
min: bigint;
raw: bigint;
signedness: string;
totalBits: number;
};
[SOLANA_ERROR__FS__UNSUPPORTED_ENVIRONMENT]: {
operation: string;
};
Expand Down
38 changes: 38 additions & 0 deletions packages/errors/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ import {
SOLANA_ERROR__CRYPTO__RANDOM_VALUES_FUNCTION_UNIMPLEMENTED,
SOLANA_ERROR__FAILED_TO_SEND_TRANSACTION,
SOLANA_ERROR__FAILED_TO_SEND_TRANSACTIONS,
SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW,
SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO,
SOLANA_ERROR__FIXED_POINTS__FRACTIONAL_BITS_EXCEED_TOTAL_BITS,
SOLANA_ERROR__FIXED_POINTS__INVALID_DECIMALS,
SOLANA_ERROR__FIXED_POINTS__INVALID_FRACTIONAL_BITS,
SOLANA_ERROR__FIXED_POINTS__INVALID_STRING,
SOLANA_ERROR__FIXED_POINTS__INVALID_TOTAL_BITS,
SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO,
SOLANA_ERROR__FIXED_POINTS__MALFORMED_RAW_VALUE,
SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH,
SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS,
SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED,
SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE,
SOLANA_ERROR__FS__UNSUPPORTED_ENVIRONMENT,
SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_ACCOUNTS,
SOLANA_ERROR__INSTRUCTION__EXPECTED_TO_HAVE_DATA,
Expand Down Expand Up @@ -395,6 +408,31 @@ export const SolanaErrorMessages: Readonly<{
[SOLANA_ERROR__CRYPTO__RANDOM_VALUES_FUNCTION_UNIMPLEMENTED]: 'No random values implementation could be found.',
[SOLANA_ERROR__FAILED_TO_SEND_TRANSACTION]: 'Failed to send transaction$causeMessage',
[SOLANA_ERROR__FAILED_TO_SEND_TRANSACTIONS]: 'Failed to send transactions$causeMessages',
[SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW]:
'Fixed-point operation `$operation` of kind `$kind` overflowed. Expected a raw bigint in [$min, $max], got $result.',
[SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO]:
'Fixed-point division by zero for value of kind `$kind` ($signedness, $totalBits bits).',
[SOLANA_ERROR__FIXED_POINTS__FRACTIONAL_BITS_EXCEED_TOTAL_BITS]:
'`fractionalBits` ($fractionalBits) must not exceed `totalBits` ($totalBits).',
[SOLANA_ERROR__FIXED_POINTS__INVALID_DECIMALS]:
'Invalid `decimals`. Expected a non-negative integer, got $decimals.',
[SOLANA_ERROR__FIXED_POINTS__INVALID_FRACTIONAL_BITS]:
'Invalid `fractionalBits`. Expected a non-negative integer, got $fractionalBits.',
[SOLANA_ERROR__FIXED_POINTS__INVALID_STRING]: 'Invalid string `$input` for fixed-point value of kind `$kind`.',
[SOLANA_ERROR__FIXED_POINTS__INVALID_TOTAL_BITS]:
'Invalid `totalBits`. Expected a positive integer, got $totalBits.',
[SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO]:
'Invalid ratio $numerator/$denominator for fixed-point value of kind `$kind`. Denominator must be non-zero.',
[SOLANA_ERROR__FIXED_POINTS__MALFORMED_RAW_VALUE]:
'Fixed-point value of kind `$kind` has a malformed `raw` field. Expected a bigint, got `$raw`.',
[SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH]:
'Fixed-point `$operation` operation expected $expectedKind ($expectedSignedness, $expectedTotalBits bits, $expectedScale $expectedScaleLabel); got $actualKind ($actualSignedness, $actualTotalBits bits, $actualScale $actualScaleLabel).',
[SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS]:
'Fixed-point operation `$operation` of kind `$kind` cannot be performed exactly; pass a rounding mode other than `strict` to allow a rounded result.',
[SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED]:
'Fixed-point codec of kind `$kind` requires `totalBits` to be a multiple of 8; got $totalBits.',
[SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE]:
'Fixed-point value of kind `$kind` is out of range for $signedness $totalBits-bit storage. Expected a raw bigint in [$min, $max], got $raw.',
[SOLANA_ERROR__FS__UNSUPPORTED_ENVIRONMENT]:
'Filesystem operation `$operation` is not supported in this environment.',
[SOLANA_ERROR__INSTRUCTION_ERROR__ACCOUNT_ALREADY_INITIALIZED]: 'Instruction requires an uninitialized account',
Expand Down
Loading