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.

npm install grpc-errors
INSTALL
IMPORT
SIG · GRPC-ERRORS
G
grpc-errors
communicationjavascriptv1.1.6
harness data pending
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.

AlreadyExistsError
import { AlreadyExistsError } from 'grpc-errors'
const AlreadyExistsError = require('grpc-errors').AlreadyExistsError
Named ESM import works; CommonJS require with destructuring is also fine but less typical.
grpcErrors
import * as grpcErrors from 'grpc-errors'
const grpcErrors = require('grpc-errors')
Default import as namespace works; CommonJS require works but is deprecated in ESM projects.
CancelledError
import { CancelledError } from 'grpc-errors'
Available as named export. No common mistake beyond using correct name.

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 issues
deprecatedPackage last updated in 2019; no new releases since.
fix
Consider using @grpc/grpc-js's built-in status object or gRPC error utilities.
affects: >=1.0.0
gotchaThe 'grpc' package (protobuf.js based) is a peer dependency; if using @grpc/grpc-js, errors may not be fully compatible.
fix
Install peer dep: npm install grpc (the older one) or migrate to @grpc/grpc-js and manually create status errors.
affects: >=1.0.0
gotchaError names (e.g., AlreadyExistsError) are not standard gRPC wire format; they are JS Error subclass instances with a code property.
fix
Use the .code property (e.g., grpc.status.ALREADY_EXISTS) for interop.
affects: >=1.0.0
breakingNo TypeScript declaration files shipped until v1.1.0; earlier versions caused TS errors.
fix
Upgrade to 1.1.0+ or write own typings.
affects: <1.1.0
Errors
Common errors & fixes
Error: Cannot find module 'grpc'
Missing peer dependency 'grpc'
fix
npm install grpc
TypeError: grpcErrors.AlreadyExistsError is not a constructor
Importing as default instead of named export
fix
Use `import { AlreadyExistsError } from 'grpc-errors'`
Property 'code' does not exist on type 'Error'
TypeScript not recognizing gRPC error properties
fix
Update to v1.1.0+ which includes typings, or add custom type declaration
Upgrade
Version history
1.1.6latest on npm
Audit
Dependencies
grpcrequiredPeer dependency required at runtime to produce errors compatible with gRPC context
Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
grpc-errors — npm install grpc-errors · libregistry