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
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.
fixEnsure 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.
fixWrap 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.
fixUse import syntax or configure your project as ES module (type: 'module' in package.json)
Audit
Dependencies
No dependency data recorded yet.