MCPcopy Index your code
hub / github.com/nodejs/node / serializeError

Function serializeError

lib/internal/error_serdes.js:112–155  ·  view source on GitHub ↗
(error, rememberSet = new SafeSet())

Source from the content-addressed store, hash-verified

110
111let serialize;
112function serializeError(error, rememberSet = new SafeSet()) {
113 serialize ??= require('v8').serialize;
114 if (typeof error === 'symbol') {
115 return Buffer.from(StringFromCharCode(kInspectedSymbol) + inspect(error), 'utf8');
116 }
117
118 try {
119 if (typeof error === 'object' &&
120 ObjectPrototypeToString(error) === '[object Error]') {
121 if (rememberSet.has(error)) {
122 return Buffer.from([kCircularReference]);
123 }
124 rememberSet.add(error);
125
126 const constructors = GetConstructors(error);
127 for (let i = 0; i < constructors.length; i++) {
128 const name = GetName(constructors[i]);
129 if (errorConstructorNames.has(name)) {
130 const serialized = serialize({
131 constructor: name,
132 properties: TryGetAllProperties(error, error, rememberSet),
133 });
134 return Buffer.concat([Buffer.from([kSerializedError]), serialized]);
135 }
136 }
137 }
138 } catch {
139 // Continue regardless of error.
140 }
141 try {
142 if (error != null && customInspectSymbol in error) {
143 return Buffer.from(StringFromCharCode(kCustomInspectedObject) + inspect(error), 'utf8');
144 }
145 } catch {
146 // Continue regardless of error.
147 }
148 try {
149 const serialized = serialize(error);
150 return Buffer.concat([Buffer.from([kSerializedObject]), serialized]);
151 } catch {
152 // Continue regardless of error.
153 }
154 return Buffer.from(StringFromCharCode(kInspectedError) + inspect(error), 'utf8');
155}
156
157function fromBuffer(error) {
158 return Buffer.from(TypedArrayPrototypeGetBuffer(error),

Callers 4

TryGetAllPropertiesFunction · 0.70
wrapMessageFunction · 0.50
v8-serializer.jsFile · 0.50

Calls 10

GetConstructorsFunction · 0.85
GetNameFunction · 0.85
TryGetAllPropertiesFunction · 0.85
concatMethod · 0.80
inspectFunction · 0.70
hasMethod · 0.65
addMethod · 0.65
requireFunction · 0.50
serializeFunction · 0.50
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…