@dabble/patches 0.5.11 → 0.5.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,5 +2,15 @@ declare class StatusError extends Error {
2
2
  code: number;
3
3
  constructor(code: number, message: string);
4
4
  }
5
+ /**
6
+ * Error thrown when the JSON-RPC client receives a message that cannot be parsed as JSON.
7
+ * This typically indicates a server-side error (HTTP 500, load balancer timeout, etc.)
8
+ * that returned plain text instead of a JSON-RPC response.
9
+ */
10
+ declare class JSONRPCParseError extends Error {
11
+ readonly rawMessage: string;
12
+ readonly parseError: Error;
13
+ constructor(rawMessage: string, parseError: Error);
14
+ }
5
15
 
6
- export { StatusError };
16
+ export { JSONRPCParseError, StatusError };
package/dist/net/error.js CHANGED
@@ -5,6 +5,18 @@ class StatusError extends Error {
5
5
  this.code = code;
6
6
  }
7
7
  }
8
+ class JSONRPCParseError extends Error {
9
+ rawMessage;
10
+ parseError;
11
+ constructor(rawMessage, parseError) {
12
+ const truncated = rawMessage.slice(0, 200) + (rawMessage.length > 200 ? "..." : "");
13
+ super(`Failed to parse JSON-RPC response: ${truncated}`);
14
+ this.name = "JSONRPCParseError";
15
+ this.rawMessage = rawMessage;
16
+ this.parseError = parseError;
17
+ }
18
+ }
8
19
  export {
20
+ JSONRPCParseError,
9
21
  StatusError
10
22
  };
@@ -57,6 +57,11 @@ declare class JSONRPCClient {
57
57
  * @param data - The raw message data received from the transport
58
58
  */
59
59
  private handleMessage;
60
+ /**
61
+ * Rejects all pending requests with the given error.
62
+ * Used when we receive an unparseable message, indicating the server is in a bad state.
63
+ */
64
+ private rejectAllPending;
60
65
  }
61
66
 
62
67
  export { JSONRPCClient };
@@ -1,5 +1,6 @@
1
1
  import "../../chunk-IZ2YBCUP.js";
2
2
  import { signal } from "../../event-signal.js";
3
+ import { JSONRPCParseError } from "../error.js";
3
4
  class JSONRPCClient {
4
5
  /**
5
6
  * Creates a new JSON-RPC client instance.
@@ -90,7 +91,23 @@ class JSONRPCClient {
90
91
  }
91
92
  console.warn("Received unexpected message format:", message);
92
93
  } catch (error) {
94
+ const parseError = new JSONRPCParseError(
95
+ data,
96
+ error instanceof Error ? error : new Error(String(error))
97
+ );
93
98
  console.error("Failed to parse incoming message:", data, error);
99
+ this.rejectAllPending(parseError);
100
+ }
101
+ }
102
+ /**
103
+ * Rejects all pending requests with the given error.
104
+ * Used when we receive an unparseable message, indicating the server is in a bad state.
105
+ */
106
+ rejectAllPending(error) {
107
+ const pendingRequests = Array.from(this.pending.entries());
108
+ this.pending.clear();
109
+ for (const [, { reject }] of pendingRequests) {
110
+ reject(error);
94
111
  }
95
112
  }
96
113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dabble/patches",
3
- "version": "0.5.11",
3
+ "version": "0.5.12",
4
4
  "description": "Immutable JSON Patch implementation based on RFC 6902 supporting operational transformation and last-writer-wins",
5
5
  "author": "Jacob Wright <jacwright@gmail.com>",
6
6
  "bugs": {