fetch-signal
A fetch(...) without a signal.
Why: nothing can stop such a request. If the server accepts the connection and never answers, the promise stays pending: browsers set no time limit, and Node waits 5 minutes for the response headers (and again whenever the body stalls). Whatever awaits it waits too: a request handler holds its connection, a job queue stops moving, a spinner spins. Guide: Async.
✕ Rejectedfetch-signal
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { mapErr, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
export type RequestError = Enum<{ Network: { cause: unknown } }>;
export const RequestError = constructors<RequestError>();
const network = (cause: unknown): RequestError => RequestError.Network({ cause });
export async function loadUser(id: string): Promise<Result<Response, RequestError>> {
return mapErr(await unsafeAsync(() => fetch(`/api/users/${id}`)), network);
}ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { mapErr, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
export type RequestError = Enum<{ Network: { cause: unknown } }>;
export const RequestError = constructors<RequestError>();
const network = (cause: unknown): RequestError => ({ tag: "Network", cause } satisfies RequestError as RequestError);
export async function loadUser(id: string): Promise<Result<Response, RequestError>> {
return mapErr(await unsafeAsync(() => fetch(`/api/users/${id}`)), network);
}✅ Accepted: a time limit, the caller's signal, or both
✓ Accepted0 diagnostics
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { mapErr, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
export type RequestError = Enum<{ Network: { cause: unknown } }>;
export const RequestError = constructors<RequestError>();
const network = (cause: unknown): RequestError => RequestError.Network({ cause });
export async function loadUser(id: string): Promise<Result<Response, RequestError>> {
return mapErr(await unsafeAsync(() => fetch(`/api/users/${id}`, { signal: AbortSignal.timeout(10_000) })), network);
}
export async function loadUserFor(id: string, signal: AbortSignal): Promise<Result<Response, RequestError>> {
const limit = AbortSignal.any([signal, AbortSignal.timeout(10_000)]);
return mapErr(await unsafeAsync(() => fetch(`/api/users/${id}`, { signal: limit })), network);
}ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { mapErr, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
export type RequestError = Enum<{ Network: { cause: unknown } }>;
export const RequestError = constructors<RequestError>();
const network = (cause: unknown): RequestError => ({ tag: "Network", cause } satisfies RequestError as RequestError);
export async function loadUser(id: string): Promise<Result<Response, RequestError>> {
return mapErr(await unsafeAsync(() => fetch(`/api/users/${id}`, { signal: AbortSignal.timeout(10_000) })), network);
}
export async function loadUserFor(id: string, signal: AbortSignal): Promise<Result<Response, RequestError>> {
const limit = AbortSignal.any([signal, AbortSignal.timeout(10_000)]);
return mapErr(await unsafeAsync(() => fetch(`/api/users/${id}`, { signal: limit })), network);
}fetch also rejects when the network fails (unhandled-failure), so the examples wrap it in unsafeAsync.
When it times out, fetch rejects with a TimeoutError DOMException; when the caller's signal aborts, with the signal's reason. withTimeout from @evobug_com/safe-ts-std/async turns both into values you match on (std helpers). Create the timeout for each request: AbortSignal.timeout(ms) starts counting when it is created, so one made at module level has expired for every request after the first few seconds.
Any signal property counts, also one that comes from an object spread into the options, if the checker can see that object:
✕ Rejectedfetch-signal
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { mapErr, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
export type RequestError = Enum<{ Network: { cause: unknown } }>;
export const RequestError = constructors<RequestError>();
const network = (cause: unknown): RequestError => RequestError.Network({ cause });
const json = { headers: { accept: "application/json" } };
export async function search(query: string): Promise<Result<Response, RequestError>> {
const url = `/api/search?${new URLSearchParams({ q: query })}`;
return mapErr(await unsafeAsync(() => fetch(url, { ...json, method: "GET" })), network);
}ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { mapErr, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
export type RequestError = Enum<{ Network: { cause: unknown } }>;
export const RequestError = constructors<RequestError>();
const network = (cause: unknown): RequestError => ({ tag: "Network", cause } satisfies RequestError as RequestError);
const json = { headers: { accept: "application/json" } };
export async function search(query: string): Promise<Result<Response, RequestError>> {
const url = `/api/search?${new URLSearchParams({ q: query })}`;
return mapErr(await unsafeAsync(() => fetch(url, { ...json, method: "GET" })), network);
}✓ Accepted0 diagnostics
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { mapErr, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
export type RequestError = Enum<{ Network: { cause: unknown } }>;
export const RequestError = constructors<RequestError>();
const network = (cause: unknown): RequestError => RequestError.Network({ cause });
const json = { headers: { accept: "application/json" } };
export async function search(query: string, signal: AbortSignal): Promise<Result<Response, RequestError>> {
const url = `/api/search?${new URLSearchParams({ q: query })}`;
return mapErr(await unsafeAsync(() => fetch(url, { ...json, method: "GET", signal })), network);
}ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { mapErr, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
export type RequestError = Enum<{ Network: { cause: unknown } }>;
export const RequestError = constructors<RequestError>();
const network = (cause: unknown): RequestError => ({ tag: "Network", cause } satisfies RequestError as RequestError);
const json = { headers: { accept: "application/json" } };
export async function search(query: string, signal: AbortSignal): Promise<Result<Response, RequestError>> {
const url = `/api/search?${new URLSearchParams({ q: query })}`;
return mapErr(await unsafeAsync(() => fetch(url, { ...json, method: "GET", signal })), network);
}Quick fixes: Pass the signal in scope (when a binding named signal is visible) · Time out after 10 s (signal: AbortSignal.timeout(10_000); change the number to what the request can take).
A controller made for a request isn't a resource unreleased-resource follows (only one whose signal is in a listener's options is): a request nothing can stop is this rule's.
What the rule can't see: options or requests it can't look into: a parameter (init: RequestInit, request: Request), a value from another module or a function call, fetch(event.request). Those are accepted, since they may carry their own signal. It only knows the global fetch, and the wrappers you list (below). And it doesn't check that the signal ever aborts: new AbortController().signal passed and never aborted is accepted too.
Request wrappers
Requests that go through an axios instance or a function of your own are checked when package.json lists them:
jsonc
"safe-ts": { "requestFunctions": ["api", "request"] }An entry matches a call written that way (request(...)) and the methods called on it (api.get(...), api.post(...)). Such a call is reported when its first argument is a URL (a string, a template, a URL) and none of the objects after it has a signal or a timeout (axios' time limit): api.get(/users/${id}), api.post("/users", { name }). Arguments it can't see into (a variable, a spread, a call) are accepted, as for fetch. List a wrapper only if it doesn't set a time limit of its own (axios.create({ timeout })). No quick fix: where the options go depends on the wrapper.
A useTask callback that never passes its signal on is unused-task-signal (idiomatic).