Skip to content

Commit 88ddd0c

Browse files
dk1aalvrs
andauthored
fix(common): improve codegen error visibility (#3662)
Co-authored-by: alvarius <[email protected]>
1 parent 6bb6a79 commit 88ddd0c

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

.changeset/giant-terms-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/common": patch
3+
---
4+
5+
Improved surfacing of errors during code generation.

packages/common/src/codegen/utils/formatAndWrite.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import fs from "node:fs/promises";
22
import path from "node:path";
33
import { formatSolidity, formatTypescript } from "./format";
4-
import { debug } from "../debug";
4+
import { debug, error } from "../debug";
55

66
/**
77
* Formats solidity code using prettier and write it to a file
8-
* @param output solidity code
8+
* @param content solidity code
99
* @param fullOutputPath full path to the output file
1010
* @param logPrefix prefix for debug logs
1111
*/
12-
export async function formatAndWriteSolidity(output: string, fullOutputPath: string, logPrefix: string): Promise<void> {
13-
const formattedOutput = await formatSolidity(output);
14-
12+
export async function formatAndWriteSolidity(
13+
content: string,
14+
fullOutputPath: string,
15+
logPrefix: string,
16+
): Promise<void> {
17+
let output = content;
18+
try {
19+
output = await formatSolidity(output);
20+
} catch (e) {
21+
error(`Error while attempting to format ${fullOutputPath}`, e);
22+
}
1523
await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });
16-
17-
await fs.writeFile(fullOutputPath, formattedOutput);
24+
await fs.writeFile(fullOutputPath, output);
1825
debug(`${logPrefix}: ${fullOutputPath}`);
1926
}
2027

0 commit comments

Comments
 (0)