# @fuel-ts/errors

> Error class and error codes that the fuels-ts library throws

Latest version **0.103.0** (published 2026-01-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @fuel-ts/errors
pnpm add @fuel-ts/errors
yarn add @fuel-ts/errors
bun add @fuel-ts/errors
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; popular repo.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.103.0 |
| Published | 2026-01-30 |
| First published | 2023-08-22 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^20.0.0 \|\| ^22.0.0 \|\| ^24.0.0 |
| Dependencies | 1 |
| Unpacked size | 143 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 42977 |
| Author | Fuel Labs |
| Maintainers | fuel-ci |

## Links

- npm: https://www.npmjs.com/package/@fuel-ts/errors
- Repository: https://github.com/FuelLabs/fuels-ts
- Homepage: https://github.com/FuelLabs/fuels-ts#readme
- Issues: https://github.com/FuelLabs/fuels-ts/issues
- npm.io page: https://npm.io/package/@fuel-ts/errors

## Dependencies (1)

- [@fuel-ts/versions](https://npm.io/package/@fuel-ts/versions.md) 0.103.0

## Recent versions

- 0.103.0 (latest) — 2026-01-30
- 0.0.0-next-20250207140505 (next) — 2025-02-07
- 0.102.0 — 2025-10-31
- 0.101.3 — 2025-07-22
- 0.101.2 — 2025-06-10
- 0.101.1 — 2025-05-29
- 0.101.0 — 2025-05-19
- 0.100.6 — 2025-05-07
- 0.100.5 — 2025-05-06
- 0.100.4 — 2025-04-29
- 0.100.3 — 2025-04-14
- 0.100.2 — 2025-04-03
- 0.100.1 — 2025-03-19
- 0.100.0 — 2025-03-17
- 0.0.0-next-20250207104530 — 2025-02-07
- … 2628 more at https://npm.io/package/@fuel-ts/errors/versions

## README

# `@fuel-ts/errors`

**@fuel-ts/errors** is a sub-module for interacting with **Fuel**.

This package contains core utilities regarding throwing errors internally inside of the `fuels-ts` SDK.

# Table of contents

- [Documentation](#documentation)
- [Usage](#usage)
  - [Installation](#installation)
  - [Internal usage](#internal-usage)
  - [Test utilities](#test-utilities)
  - [External usage](#external-usage)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)

## Documentation

<!-- TODO: Replace this link with specific docs for this package if and when we re-introduce a API reference section to our docs -->

See [Fuels-ts Documentation](https://docs.fuel.network/docs/fuels-ts/)

## Usage

### Installation

```sh
pnpm add @fuel-ts/errors
# or
npm add @fuel-ts/errors
```

### Internal usage

```ts
import { FuelError, ErrorCodes } from "@fuel-ts/error";

export function singleImport() {
  throw new FuelError(FuelError.CODES.INVALID_DATA, "Invalid data");
}

export function multipleImports() {
  throw new FuelError(ErrorCodes.INVALID_DATA, "Invalid data");
}
```

### Test Utilities

You can use the `expectToThrowFuelError` test utility when asserting errors.

```ts
// can also be imported from `fuels` when using the umbrella package
import { expectToThrowFuelError } from "@fuel-ts/errors";

import { myFn } from "...";

describe('this and that' () => {
  const code = FuelError.CODES.INVALID_DATA;

  it("should throw FuelError", async () => {
    const expected = new FuelError(code);
    await expectToThrowFuelError(() => myFn(), expected);
  });

  it("should throw something else", async () => {
    const expected = new FuelError(code);
    const fn = () => expectToThrowFuelError(() => myFn(), expected)
    await expect(fn).rejects.toThrow('Something else');
  });
})
```

### External usage

```ts
import { FuelError, Provider } from "fuels";

type Locale = "pt-BR" | "bs-BA" | "en-GB";

const currentLocale: Locale = "pt-BR";

const i18nDict = {
  pt-BR: {
    [FuelError.CODES.INVALID_DATA]: "Dados inválidos",
  },
  bs-BA: {
    [FuelError.CODES.INVALID_DATA]: "Nevažeći podaci",
  },
  en-GB: {
    [FuelError.CODES.INVALID_DATA]: "Invalid data",
  },
};

function translateError(e: unknown) {
  const { code } = FuelError.parse(e);
  return i18nDict[currentLocale][code];
}

function main() {
  try {
    const p = new Provider("0004:tƨoʜlɒɔol//:qttʜ");
    console.log(p);
  } catch (e) {
    const prettyError = translateError(e);
    console.log({ prettyError });
  }
};
```

## Contributing

In order to contribute to `@fuel-ts/errors`, please see the main [fuels-ts](https://github.com/FuelLabs/fuels-ts) monorepo.

## Changelog

The `@fuel-ts/errors` changelog can be found at [CHANGELOG](./CHANGELOG.md).

## License

The primary license for `@fuel-ts/errors` is `Apache 2.0`, see [LICENSE](./LICENSE).

---
_Source: https://npm.io/package/@fuel-ts/errors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
