MCPcopy
hub / github.com/coder/mux / attachStreamErrorHandler

Function attachStreamErrorHandler

src/node/utils/streamErrors.ts:44–72  ·  view source on GitHub ↗
(
  emitter: NodeJS.EventEmitter,
  label: string,
  options: StreamErrorHandlerOptions = {}
)

Source from the content-addressed store, hash-verified

42}
43
44export function attachStreamErrorHandler(
45 emitter: NodeJS.EventEmitter,
46 label: string,
47 options: StreamErrorHandlerOptions = {}
48): () => void {
49 const handler = (error: unknown) => {
50 const normalized = normalizeError(error);
51 const info: StreamErrorInfo = {
52 label,
53 code: getErrorCode(error),
54 message: normalized.message,
55 };
56
57 if (isIgnorableStreamError(error)) {
58 options.logger?.debug("Ignored stream error", info, normalized);
59 options.onIgnorable?.(normalized, info);
60 return;
61 }
62
63 options.logger?.warn("Stream error", info, normalized);
64 options.onUnexpected?.(normalized, info);
65 };
66
67 emitter.on("error", handler);
68
69 return () => {
70 emitter.removeListener("error", handler);
71 };
72}

Callers 4

execFunction · 0.90
attachMethod · 0.90
constructorMethod · 0.90
createOrpcServerFunction · 0.90

Calls 1

onMethod · 0.80

Tested by

no test coverage detected