Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions __tests__/prettier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,10 @@ describe('prettier', () => {
expect(await wrapDescription(undefined, undefined as unknown as string[])).toEqual([]);
});

// Prettier's markdown parser accepts malformed markdown — unterminated
// fences and invalid json/yaml fence bodies all format without throwing —
// so the catch is only reachable via a non-string value slipping past the
// type. It swallows the error rather than propagating, which leaves
// formattedString empty and still appends one bare prefix line.
//
// The logger is spied on rather than left to run: LogTask.error emits a
// `::error::` line, which GitHub Actions turns into an error annotation on
// an otherwise-passing run.
it('logs and falls back to a single prefix line when formatting throws', async () => {
it('propagates formatter failures after logging the error', async () => {
const logged = vi.spyOn(LogTask.prototype, 'error').mockImplementation(() => {});

try {
const result = await wrapDescription(42 as unknown as string, ['line 1'], '# ');

expect(result).toEqual(['line 1', '# ']);
await expect(wrapDescription(42 as unknown as string, ['line 1'], '# ')).rejects.toThrow();
expect(logged).toHaveBeenCalledOnce();
} finally {
logged.mockRestore();
Expand Down
1 change: 1 addition & 0 deletions src/prettier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export async function wrapDescription(
});
} catch (error) {
log.error(`${String(error)}`);
throw error;
}

content.push(...formattedString.split('\n').map((line) => prefix + line.replace(prefix, '')));
Expand Down
1 change: 1 addition & 0 deletions src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default async function save(inputs: Inputs, log: LogTask): Promise<void>
await docsConfig.save(inputs.configPath);
} catch (error) {
log.error(`${String(error)}`);
throw error;
Comment thread
Jamie-BitFlight marked this conversation as resolved.
}
}
}
Loading