Registry / communication / grpc-errors

grpc-errors

JSON →
library1.1.6jsnpmunverified

A utility library for creating gRPC error objects with standard gRPC status codes. Version 1.1.6 is the latest release, with no recent updates since 2019. It provides a simple factory for all 16 gRPC error types (e.g., AlreadyExistsError, NotFoundError) as error subclasses. Unlike manually constructing gRPC errors, this package ensures correct status codes and messages. It ships TypeScript types and supports ESM via import. Suitable for Node.js gRPC servers.

communication
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Named ESM import works; CommonJS require with destructuring is also fine but less typical.

import { AlreadyExistsError } from 'grpc-errors'

Default import as namespace works; CommonJS require works but is deprecated in ESM projects.

import * as grpcErrors from 'grpc-errors'

Available as named export. No common mistake beyond using correct name.

import { CancelledError } from 'grpc-errors'

Demonstrates importing and throwing various gRPC errors, accessing code, message, and name properties.

import { AlreadyExistsError, NotFoundError, InternalError } from 'grpc-errors'; // Create and throw a gRPC error function createFile(name: string) { if (!name) { throw new NotFoundError('File not found'); } // ... throw new AlreadyExistsError(`File ${name} already exists`); } try { createFile('test.txt'); } catch (err) { console.log(err.code); // 6 for AlreadyExists console.log(err.message); // File test.txt already exists console.log(err.name); // AlreadyExistsError } // Alternatively, use with grpc sendError method // server.sendError(call, new InternalError('Server error'));
Debug
Known footguns
deprecatedPackage last updated in 2019; no new releases since.
gotchaThe 'grpc' package (protobuf.js based) is a peer dependency; if using @grpc/grpc-js, errors may not be fully compatible.
gotchaError names (e.g., AlreadyExistsError) are not standard gRPC wire format; they are JS Error subclass instances with a code property.
breakingNo TypeScript declaration files shipped until v1.1.0; earlier versions caused TS errors.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources