Skip to content

Commit bdb0092

Browse files
committed
Remove assertNoErrorInCatch and update references
Deleted the assertNoErrorInCatch helper from Assert.ts and removed its usage from WebSocket.ts and documentation. Errors in Promise catch blocks now throw directly, simplifying error handling and reducing unnecessary abstraction.
1 parent 758ed20 commit bdb0092

4 files changed

Lines changed: 4 additions & 23 deletions

File tree

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const formatCurrencyCodeError = createTypeErrorFormatter<CurrencyCodeError>(
179179
- Use for catching developer mistakes eagerly (e.g., invalid configuration)
180180

181181
```ts
182-
import { assert, assertNonEmptyArray, assertNoErrorInCatch } from "./Assert.js";
182+
import { assert, assertNonEmptyArray } from "./Assert.js";
183183

184184
// ✅ Good example
185185
const length = buffer.getLength();

apps/web/src/app/(landing)/blog/the-copy-paste-typescript-standard-library/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ It’s half a joke and half the truth. Programmers should understand the code th
8686

8787
- [Result](https://github.com/evoluhq/evolu/blob/main/packages/common/src/Result.ts) (type‑safe errors)
8888
- [Brand](https://github.com/evoluhq/evolu/blob/main/packages/common/src/Brand.ts) (prevents mixing incompatible values, e.g., `type UserId = string & Brand<"UserId">`)
89-
- [Assert](https://github.com/evoluhq/evolu/blob/main/packages/common/src/Assert.ts) (fail‑fast helpers: `assert`, `assertNonEmptyArray`, `assertNoErrorInCatch`)
89+
- [Assert](https://github.com/evoluhq/evolu/blob/main/packages/common/src/Assert.ts) (fail‑fast helpers: `assert`, `assertNonEmptyArray`)
9090
- [Array](https://github.com/evoluhq/evolu/blob/main/packages/common/src/Array.ts) (non‑empty arrays and helpers: `NonEmptyArray`, `isNonEmptyArray`, `appendToArray`)
9191
- [Function](https://github.com/evoluhq/evolu/blob/main/packages/common/src/Function.ts) (small function utils: `exhaustiveCheck`, `identity`, `LazyValue`)
9292
- [Object](https://github.com/evoluhq/evolu/blob/main/packages/common/src/Object.ts) (object helpers: `isPlainObject`, `mapObject`, `objectToEntries`, `excludeProp`)

packages/common/src/Assert.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,3 @@ export const assertNonEmptyReadonlyArray: <T>(
9696
) => {
9797
assert(arr.length > 0, message);
9898
};
99-
100-
/**
101-
* Asserts no error reaches a `.catch` block, throwing a developer error if it
102-
* does. Used in Promise chains where errors indicate bugs to be fixed.
103-
*
104-
* ### Example
105-
*
106-
* ```ts
107-
* Promise.reject("test").catch((e) =>
108-
* assertNoErrorInCatch("WebSocket retry", e),
109-
* );
110-
* ```
111-
*/
112-
export function assertNoErrorInCatch(context: string, error: unknown): never {
113-
throw new Error(
114-
`Error in ${context}: an unexpected error reached a catch block and requires a fix`,
115-
{ cause: error },
116-
);
117-
}

packages/common/src/WebSocket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* @module
55
*/
66

7-
import { assertNoErrorInCatch } from "./Assert.js";
87
import { constVoid } from "./Function.js";
98
import { err, ok, Result } from "./Result.js";
109
import { retry, RetryError, RetryOptions } from "./Task.js";
@@ -222,6 +221,7 @@ export const createWebSocket: CreateWebSocket = (
222221
? { type: "WebSocketConnectionError", event }
223222
: { type: "WebSocketConnectError", event };
224223
onError?.(error);
224+
225225
// Trigger reconnect only on WebSocketConnectError.
226226
if (error.type === "WebSocketConnectError") {
227227
resolve(err(error));
@@ -243,7 +243,7 @@ export const createWebSocket: CreateWebSocket = (
243243
onError?.(result.error as WebSocketError);
244244
})
245245
.catch((error: unknown) => {
246-
assertNoErrorInCatch("WebSocket retry", error);
246+
throw error;
247247
});
248248

249249
return {

0 commit comments

Comments
 (0)