{"id":47753,"library":"gerror","title":"GError","description":"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.","status":"active","version":"1.0.16","language":"javascript","source_language":"en","source_url":"https://github.com/huan/gerror","tags":["javascript","error","grpc","ecma","status","protocol buffer","typescript"],"install":[{"cmd":"npm install gerror","lang":"bash","label":"npm"},{"cmd":"yarn add gerror","lang":"bash","label":"yarn"},{"cmd":"pnpm add gerror","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package exports only named members; default import will not work.","wrong":"import GError from 'gerror'","symbol":"GError","correct":"import { GError } from 'gerror'"},{"note":"CommonJS require pattern is valid but TypeScript may require esModuleInterop. Prefer ESM import.","wrong":"const wrapAsyncError = require('gerror').wrapAsyncError","symbol":"wrapAsyncError","correct":"import { wrapAsyncError } from 'gerror'"},{"note":"Use static method .from() to wrap existing errors, not constructor. The constructor signature is different.","wrong":"const { GError } = require('gerror'); const e = new GError('test')","symbol":"GError.from","correct":"import { GError } from 'gerror'; const e = GError.from(new Error('test'))"}],"quickstart":{"code":"import { GError, wrapAsyncError } from 'gerror'\n\n// Create a GError from a standard Error\nconst original = new Error('Something went wrong')\nconst gerr = GError.from(original)\n\n// Add gRPC status code (optional)\ngerr.code = 13 // INTERNAL\n\nconsole.log(gerr.toJSON())\n// {\"name\":\"Error\",\"message\":\"Something went wrong\",\"stack\":\"...\",\"code\":13}\n\n// Wrap async functions to catch errors via callback\nconst onError = (e: any) => console.error('Caught:', e)\nconst wrap = wrapAsyncError(onError)\n\nconst asyncFunc = async () => { throw new Error('async rejection') }\nconst syncFunc = wrap(asyncFunc)\n// syncFunc is void; no unhandled rejection","lang":"typescript","description":"Shows how to create GError from standard Error, add gRPC code, serialize to JSON, and use wrapAsyncError to catch async errors."},"warnings":[{"fix":"Use GError.from(err) instead of new GError(err)","message":"Constructor signature differs from standard Error; use static GError.from() to wrap existing errors","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Ensure onError callback is properly provided to handle rejected errors","message":"wrapAsyncError is intended for converting async functions to sync; misuse may swallow rejections","severity":"deprecated","affected_versions":">=1.0"},{"fix":"Set gerr.code explicitly before calling toJSON()","message":"toJSON() will only include 'code' property if explicitly set; gRPC status not automatically inferred","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Upgrade Node.js to version 16 or later","message":"Requires Node.js >=16 due to ES module support and optional chaining usage","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"search_vec":"'2021':32 'async':49,56 'buffer':66 'class':16 'code':20 'definit':39 'differenti':41 'ecma':63 'ecmascript':10,50 'environ':51 'error':8,11,15,46,57,61 'gerror':1 'grpc':7,18,45,62 'handl':47 'integr':43 'javascript':60 'key':40 'latest':27 'librari':4 'mix':6 'oct':31 'protobuf':22 'protocol':65 'provid':12 'releas':30 'seamless':42 'serial':23 'ship':37 'stabl':28 'status':19,64 'support':54 'tojson':53 'type':38 'typescript':3,67 'unifi':14 'updat':36 'util':59 'v1.0.16':24 'version':29 'wrap':58","created_at":"2026-06-07T16:53:08.943128+00:00","updated_at":"2026-06-07T16:53:08.943128+00:00","problems":[{"fix":"Ensure Node.js version >=16","cause":"Using older Node.js version that doesn't support proper Error subclassing.","error":"TypeError: Class extends Error is not a valid constructor"},{"fix":"Wrap async function with wrapAsyncError and provide a non-throwing onError callback","cause":"wrapAsyncError was not used, or the onError callback did not handle the error.","error":"UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block"},{"fix":"Use import syntax or configure your project as ES module (type: 'module' in package.json)","cause":"Package uses ES modules; CommonJS require() may not work without bundler or Node's --experimental-modules flag.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/huan/gerror#readme","github":"https://github.com/huan/gerror","docs":null,"changelog":null,"pypi":null,"npm":"gerror","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}