INNER CODE UNIT · TypeScript

messageOf

totec448-spec/chat-on-steroids · src/main/codex/apply-patch/index.ts:143

function messageOf(error: unknown): string {
  return error instanceof Error ? error.message : String(error);
}

/**
 * Rust's `.with_context(|| ...)`: replaces the message the caller will see while keeping the
 * original error reachable as the cause.
 */
async function withContext<T>(work: Promise<T>, context: () => string): Promise<T> {
  try {
    return await work;
  } catch (error) {
    throw new Error(context(), { cause: error });
  }
}

function errorCode(error: unknown): string | undefined {
  return typeof error === 'object' && error !== null ? (error as NodeJS.ErrnoException).code : undefined;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…