unsafe-project-call
unsafe(() => f(...)) or unsafeAsync(() => f(...)) without Panic, where f is the project's own function in a checked file and the checker finds nothing it throws or rejects with. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
Why: unsafe is for code that throws: built-ins, libraries, legacy files. Checked project code reports its failures in its Result, so a throw out of it is a bug. Wrapped without Panic, the bug becomes an Err like any expected failure: it is shown as a toast, retried or ignored, and nobody learns about it. Call the function directly; to keep a bug apart from the failures you handle, pass Panic and test isPanic. Guide: Errors.
✕ Rejectedunsafe-project-call
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
type SearchError = Enum<{ NoQuery: {} }>;
const SearchError = constructors<SearchError>();
export async function search(text: string): Promise<Result<string[], SearchError>> {
return text === "" ? err(SearchError.NoQuery()) : [text];
}
export async function suggestions(text: string): Promise<string[]> {
const thrown = await unsafeAsync(() => search(text));
if (isErr(thrown)) return []; // a bug, shown as "no suggestions"
const found = thrown;
return isErr(found) ? [] : found;
}ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
type SearchError = Enum<{ NoQuery: {} }>;
const SearchError = constructors<SearchError>();
export async function search(text: string): Promise<Result<string[], SearchError>> {
return text === "" ? err(({ tag: "NoQuery" } satisfies SearchError as SearchError)) : [text];
}
export async function suggestions(text: string): Promise<string[]> {
const thrown = await unsafeAsync(() => search(text));
if (isErr(thrown)) return []; // a bug, shown as "no suggestions"
const found = thrown;
return isErr(found) ? [] : found;
}✓ Accepted0 diagnostics
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, isPanic, Panic, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
type SearchError = Enum<{ NoQuery: {} }>;
const SearchError = constructors<SearchError>();
export async function search(text: string): Promise<Result<string[], SearchError>> {
return text === "" ? err(SearchError.NoQuery()) : [text];
}
export async function suggestions(text: string): Promise<string[]> {
const found = await search(text);
return isErr(found) ? [] : found;
}
export async function guarded(text: string): Promise<string[]> {
const found = await unsafeAsync(() => search(text), Panic);
if (isPanic(found)) {
console.error("bug in search", found.reason);
return [];
}
return isErr(found) ? [] : found;
}ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, isPanic, Panic, type Result, unsafeAsync } from "@evobug_com/safe-ts-std/result";
type SearchError = Enum<{ NoQuery: {} }>;
const SearchError = constructors<SearchError>();
export async function search(text: string): Promise<Result<string[], SearchError>> {
return text === "" ? err(({ tag: "NoQuery" } satisfies SearchError as SearchError)) : [text];
}
export async function suggestions(text: string): Promise<string[]> {
const found = await search(text);
return isErr(found) ? [] : found;
}
export async function guarded(text: string): Promise<string[]> {
const found = await unsafeAsync(() => search(text), Panic);
if (isPanic(found)) {
console.error("bug in search", found.reason);
return [];
}
return isErr(found) ? [] : found;
}Not reported: a function the checker knows can throw (then unsafe is how its caller takes the failure on, and returning a Result from it is the next step), calls into legacy and // @safe-ts std files, packages and built-ins. A callback handed in by the caller (props.search(text)) isn't followed.