Registry / testing / grpc-error-status

grpc-error-status

JSON →
library1.0.1jsnpmunverified

A utility library for decoding gRPC error details from the `grpc-status-details-bin` metadata. Version 1.0.1 (stable). Works with any gRPC client library that enriches errors with the `grpc-status-details-bin` trailer, including `@grpc/grpc-js`. Parses the binary protobuf content into a JavaScript object with typed details (e.g., RetryInfo, DebugInfo). No external runtime dependencies; all required protobuf types are bundled. Simpler alternative to manually using `google-rpc` protobufs.

npm install grpc-error-status
INSTALL
IMPORT
SIG · GRPC-ERROR-STATUS
G
grpc-error-status
testingjavascriptv1.0.1
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.

parse
import { parse } from 'grpc-error-status'
const parse = require('grpc-error-status').parse
ESM import; package also supports CommonJS require() but with destructuring.
default import
import grpcStatus from 'grpc-error-status'
const grpcStatus = require('grpc-error-status')
CommonJS require returns the module, not the default export; use destructuring or import * as.
parse function
const grpcStatus = require('grpc-error-status'); const status = grpcStatus.parse(err);
const { parse } = require('grpc-error-status'); const status = parse(err);
Both work; the first is more common in CJS codebases.

Parses a gRPC error from a client call and prints the structured error details.

const grpcStatus = require('grpc-error-status'); const grpc = require('@grpc/grpc-js'); const protoLoader = require('@grpc/proto-loader'); const packageDef = protoLoader.loadSync('helloworld.proto'); const helloProto = grpc.loadPackageDefinition(packageDef).helloworld; const client = new helloProto.Greeter('localhost:50051', grpc.credentials.createInsecure()); client.sayHello({ name: 'you' }, (err, response) => { if (err) { const status = grpcStatus.parse(err); if (status) { console.log('Error details:', status.toObject()); } else { console.log('gRPC error:', err.message); } return; } console.log('Greeting:', response.message); });
Debug
Known issues
gotchaparse() returns null if the error does not have grpc-status-details-bin metadata, not undefined.
fix
Check for null explicitly with if (status !== null) or if (status != null).
affects: *
gotchaThe library only decodes the binary metadata; it does not set up error handling or interceptors.
fix
Ensure your gRPC client is configured to propagate the grpc-status-details-bin trailer (standard in @grpc/grpc-js).
affects: *
breakingDeprecated: The package uses protobufjs v6 internally; protobufjs v7 may cause compatibility issues.
fix
Pin protobufjs to v6.x in your project if you encounter issues, or use an alternative like @grpc/grpc-js error handling.
affects: <=1.0.1
Errors
Common errors & fixes
TypeError: grpcStatus.parse is not a function
Using default import style (import grpcStatus from ...) in CommonJS environment, which gives an object that doesn't have parse function.
fix
Use const { parse } = require('grpc-error-status'); or import * as grpcStatus from 'grpc-error-status' in ESM.
Cannot read properties of null (reading 'toObject')
parse() returns null and calling .toObject() on null.
fix
Check if status is not null before calling toObject().
Error: No such type: google.rpc.Status
The protobuf root was not loaded correctly; the bundled types are missing or overridden by another protobufjs instance.
fix
Ensure grpc-error-status is the only version of protobufjs used, or load types manually before calling parse().
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
protobufjsrequiredRuntime dependency for decoding protobuf binary data; bundled types rely on protobufjs loading.
Agent activity
14 hits · last 30 days
node
12
Resources
grpc-error-status — npm install grpc-error-status · libregistry