{"id":48016,"library":"grpc-error","title":"gRPC Error","description":"Utility Error class for creating gRPC error responses with status codes and metadata. Version 1.1.0 is stable with no recent releases. It extends the native Error class and integrates with gRPC status codes and Metadata. Differentiates from plain errors by supporting gRPC-specific properties like code and built-in metadata handling.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/bojand/grpc-error","tags":["javascript","protocol buffer","protobuf","grpc"],"install":[{"cmd":"npm install grpc-error","lang":"bash","label":"npm"},{"cmd":"yarn add grpc-error","lang":"bash","label":"yarn"},{"cmd":"pnpm add grpc-error","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for gRPC status codes and Metadata class","package":"@grpc/grpc-js","optional":true}],"imports":[{"note":"Package is CJS-only; does not support ESM imports directly.","wrong":"import GRPCError from 'grpc-error'","symbol":"GRPCError","correct":"const GRPCError = require('grpc-error')"},{"note":"Default export is the class; named import does not exist.","wrong":"const GRPCError = require('grpc-error').GRPCError","symbol":"GRPCError","correct":"const { GRPCError } = require('grpc-error')"},{"note":"Common usage expects 'GRPCError' as the variable name.","wrong":"const grpcError = require('grpc-error')","symbol":"GRPCError","correct":"const GRPCError = require('grpc-error')"}],"quickstart":{"code":"const GRPCError = require('grpc-error');\nconst grpc = require('@grpc/grpc-js');\n\n// Create gRPC error with status code\nconst error = new GRPCError('Invalid argument', grpc.status.INVALID_ARGUMENT);\nconsole.log(error.message); // 'Invalid argument'\nconsole.log(error.code); // 3\n\n// Create with custom code and metadata\nconst error2 = new GRPCError('Boom', 2000, { status_code: 'INVALID_TOKEN' });\nconsole.log(error2.code); // 2000\nconsole.log(error2.metadata.getMap()); // { status_code: 'INVALID_TOKEN' }","lang":"javascript","description":"Shows creating GRPCError with status code from @grpc/grpc-js and with custom code and metadata."},"warnings":[{"fix":"Use require() instead of import, or use dynamic import() as fallback.","message":"The package is CommonJS only; ESM import (import GRPCError from 'grpc-error') will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install @grpc/grpc-js as a peer dependency: npm install @grpc/grpc-js","message":"If @grpc/grpc-js is not installed, metadata property may not be fully functional or may throw.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Migrate to grpc-js native errors or use a fork.","message":"The package has not been updated since 2019; consider using gRPC's built-in error utilities or a more maintained alternative.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.1.0':17 'buffer':58 'built':52 'built-in':51 'class':5,29 'code':13,35,49 'creat':7 'differenti':38 'error':2,4,9,28,41 'extend':25 'grpc':1,8,33,45,60 'grpc-specif':44 'handl':55 'integr':31 'javascript':56 'like':48 'metadata':15,37,54 'nativ':27 'plain':40 'properti':47 'protobuf':59 'protocol':57 'recent':22 'releas':23 'respons':10 'specif':46 'stabl':19 'status':12,34 'support':43 'util':3 'version':16","created_at":"2026-06-07T16:54:29.562311+00:00","updated_at":"2026-06-07T16:54:29.562311+00:00","problems":[{"fix":"Instantiate with 'new GRPCError(...)'","cause":"Trying to call GRPCError as a function without 'new'.","error":"TypeError: Class constructor GRPCError cannot be invoked without 'new'"},{"fix":"Run: npm install @grpc/grpc-js","cause":"Missing peer dependency '@grpc/grpc-js' (or older 'grpc' package).","error":"Module not found: Can't resolve 'grpc'"},{"fix":"Ensure you require: const grpc = require('@grpc/grpc-js');","cause":"Using @grpc/grpc-js version that changed the export path.","error":"Error: grpc.Metadata is not a constructor"}],"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/bojand/grpc-error","github":"https://github.com/bojand/grpc-error","docs":null,"changelog":null,"pypi":null,"npm":"grpc-error","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","security"],"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}}