(text: string, args: readonly string[])
| 11 | } |
| 12 | |
| 13 | export function parseGhJsonLines<T>(text: string, args: readonly string[]): T[] { |
| 14 | if (!text) return []; |
| 15 | return text |
| 16 | .split("\n") |
| 17 | .filter(Boolean) |
| 18 | .map((line, index) => { |
| 19 | try { |
| 20 | return JSON.parse(line) as T; |
| 21 | } catch (error) { |
| 22 | throw new Error( |
| 23 | `Failed to parse JSON line ${index + 1} from ${summarizeGhArgs(args)}: ${formatParseError(error)}`, |
| 24 | ); |
| 25 | } |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | function formatParseError(error: unknown): string { |
| 30 | return error instanceof Error ? error.message : String(error); |
no test coverage detected