d24d11a274
- Standardized missing-file read errors and now return `File not found: <path>` for absent edit targets. - Centralized AI provider, usage, and OAuth helpers into shared modules to remove duplicated logic. - Migrated OAuth/API-key login flows to shared factory helpers and removed inline prompt/token-exchange code. - Reused shared tools and formatter utilities for discovery, stream tails, LSP batching, and source formatting. - Consolidated repeated test helpers and fixtures into shared modules, replacing inline helper duplicates.
19 lines
490 B
TypeScript
19 lines
490 B
TypeScript
/**
|
|
* Shared file-read helper for edit-mode utilities.
|
|
*
|
|
* Reads a file via Bun and rethrows ENOENT as a user-facing "File not found"
|
|
* error referencing the display path.
|
|
*/
|
|
import { isEnoent } from "@oh-my-pi/pi-utils";
|
|
|
|
export async function readEditFileText(absolutePath: string, path: string): Promise<string> {
|
|
try {
|
|
return await Bun.file(absolutePath).text();
|
|
} catch (error) {
|
|
if (isEnoent(error)) {
|
|
throw new Error(`File not found: ${path}`);
|
|
}
|
|
throw error;
|
|
}
|
|
}
|