Registry / testing / gerror

gerror

JSON →
library1.0.16jsnpmunverified

A TypeScript library that mixes gRPC Error and ECMAScript Error, providing a unified error class with gRPC status codes and protobuf serialization. v1.0.16 is the latest stable version, released Oct 2021, with no further updates. Ships type definitions. Key differentiator: seamless integration of gRPC error handling into async ECMAScript environments, with toJSON() support and async error wrapping utility.

npm install gerror
INSTALL
IMPORT
SIG · GERROR
G
gerror
testingjavascriptv1.0.16
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.

GError
import { GError } from 'gerror'
import GError from 'gerror'
This package exports only named members; default import will not work.
wrapAsyncError
import { wrapAsyncError } from 'gerror'
const wrapAsyncError = require('gerror').wrapAsyncError
CommonJS require pattern is valid but TypeScript may require esModuleInterop. Prefer ESM import.
GError.from
import { GError } from 'gerror'; const e = GError.from(new Error('test'))
const { GError } = require('gerror'); const e = new GError('test')
Use static method .from() to wrap existing errors, not constructor. The constructor signature is different.

Shows how to create GError from standard Error, add gRPC code, serialize to JSON, and use wrapAsyncError to catch async errors.

import { GError, wrapAsyncError } from 'gerror' // Create a GError from a standard Error const original = new Error('Something went wrong') const gerr = GError.from(original) // Add gRPC status code (optional) gerr.code = 13 // INTERNAL console.log(gerr.toJSON()) // {"name":"Error","message":"Something went wrong","stack":"...","code":13} // Wrap async functions to catch errors via callback const onError = (e: any) => console.error('Caught:', e) const wrap = wrapAsyncError(onError) const asyncFunc = async () => { throw new Error('async rejection') } const syncFunc = wrap(asyncFunc) // syncFunc is void; no unhandled rejection
Debug
Known issues
gotchaConstructor signature differs from standard Error; use static GError.from() to wrap existing errors
fix
Use GError.from(err) instead of new GError(err)
affects: >=1.0
deprecatedwrapAsyncError is intended for converting async functions to sync; misuse may swallow rejections
fix
Ensure onError callback is properly provided to handle rejected errors
affects: >=1.0
gotchatoJSON() will only include 'code' property if explicitly set; gRPC status not automatically inferred
fix
Set gerr.code explicitly before calling toJSON()
affects: >=1.0
gotchaRequires Node.js >=16 due to ES module support and optional chaining usage
fix
Upgrade Node.js to version 16 or later
affects: >=1.0
Errors
Common errors & fixes
TypeError: Class extends Error is not a valid constructor
Using older Node.js version that doesn't support proper Error subclassing.
fix
Ensure Node.js version >=16
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block
wrapAsyncError was not used, or the onError callback did not handle the error.
fix
Wrap async function with wrapAsyncError and provide a non-throwing onError callback
SyntaxError: Cannot use import statement outside a module
Package uses ES modules; CommonJS require() may not work without bundler or Node's --experimental-modules flag.
fix
Use import syntax or configure your project as ES module (type: 'module' in package.json)
Upgrade
Version history
1.0.16latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
packagegerror
gerror — npm install gerror · libregistry