Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance error handling to support third-party tools #509

Merged
merged 23 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c7cfa37
Enhance error handling to support third-party tools
rahulyadav-57 Jun 28, 2024
c46cc8a
Merge branch 'main' into enhance-error-handling
rahulyadav-57 Jun 28, 2024
17ce414
fix: remove unused consoleLogger and jest mocks
rahulyadav-57 Jun 28, 2024
f74838a
Merge branch 'main' into enhance-error-handling
rahulyadav-57 Jul 3, 2024
a457c81
Add TactErrorCollection type
rahulyadav-57 Jul 3, 2024
3029053
Address review comments
rahulyadav-57 Jul 5, 2024
f51875b
Merge branch 'main' into enhance-error-handling
rahulyadav-57 Jul 5, 2024
6d7e69f
feat: add `-q`/`--quiet` flags to suppress compiler log output
novusnota Jul 5, 2024
4e96bbd
chore: CHANGELOG
novusnota Jul 5, 2024
d8d1d2b
chore: formatting
novusnota Jul 5, 2024
0bb4e92
Update src/pipeline/build.ts
anton-trunov Jul 5, 2024
d10df50
Update src/pipeline/build.ts
anton-trunov Jul 5, 2024
9f7f119
Update scripts/prepare.ts
anton-trunov Jul 5, 2024
17999a7
Update src/pipeline/build.ts
anton-trunov Jul 5, 2024
701a340
Update src/pipeline/build.ts
anton-trunov Jul 5, 2024
824ac30
Update src/node.ts
anton-trunov Jul 5, 2024
f621b22
Update src/pipeline/build.ts
anton-trunov Jul 5, 2024
f1de083
Update src/pipeline/build.ts
anton-trunov Jul 5, 2024
94d8b94
Update scripts/prepare.ts
anton-trunov Jul 5, 2024
3d9970d
Merge branch 'main' into enhance-error-handling
anton-trunov Jul 5, 2024
576b354
fix prepare.ts
anton-trunov Jul 5, 2024
8d8b772
fix build.ts
anton-trunov Jul 5, 2024
b6dcbae
chore: simplified a bit more
novusnota Jul 5, 2024
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
134 changes: 72 additions & 62 deletions scripts/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,74 +15,84 @@ import { __DANGER__disableVersionNumber } from "../src/pipeline/version";

const logger = new Logger();

// Compile projects
if (!(await run({ configPath: __dirname + "/../tact.config.json" })).ok) {
console.error("Tact projects compilation failed");
process.exit(1);
}

// Verify projects
for (const pkgPath of glob.sync(
path.normalize(
path.resolve(__dirname, "..", "examples", "output", "*.pkg"),
),
)) {
const res = await verify({ pkg: fs.readFileSync(pkgPath, "utf-8") });
if (!res.ok) {
console.error("Failed to verify " + pkgPath + ": " + res.error);
process.exit(1);
try {
// Compile projects
const compileResult = await run({
configPath: path.join(__dirname, "../tact.config.json"),
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
});
if (!compileResult.ok) {
throw new Error("Tact projects compilation failed");
}
}

// Compile func files
for (const p of [{ path: __dirname + "/../func/" }]) {
const recs = fs.readdirSync(p.path);
for (const r of recs) {
if (!r.endsWith(".fc")) {
continue;
// Verify projects
for (const pkgPath of glob.sync(
path.normalize(
path.resolve(__dirname, "..", "examples", "output", "*.pkg"),
),
)) {
const res = await verify({
pkg: fs.readFileSync(pkgPath, "utf-8"),
});
if (!res.ok) {
throw new Error(`Failed to verify ${pkgPath}: ${res.error}`);
}
}

// Precompile
console.log("Processing " + p.path + r);
let c: FuncCompilationResult;
try {
const stdlibPath = path.resolve(
__dirname,
"..",
"stdlib",
"stdlib.fc",
);
const stdlib = fs.readFileSync(stdlibPath, "utf-8");
const code = fs.readFileSync(p.path + r, "utf-8");
c = await funcCompile({
entries: [stdlibPath, p.path + r],
sources: [
{
path: stdlibPath,
content: stdlib,
},
{
path: p.path + r,
content: code,
},
],
logger: logger,
});
if (!c.ok) {
logger.error(c.log);
process.exit(1);
// Compile func files
for (const p of [{ path: path.join(__dirname, "/../func/") }]) {
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
const recs = fs.readdirSync(p.path);
for (const r of recs) {
if (!r.endsWith(".fc")) {
continue;
}
} catch (e) {
logger.error(e as Error);
logger.error("Failed");
process.exit(1);
}
fs.writeFileSync(p.path + r + ".fift", c.fift!);
fs.writeFileSync(p.path + r + ".cell", c.output!);

// Cell -> Fift decompiler
const source = decompileAll({ src: c.output! });
fs.writeFileSync(p.path + r + ".rev.fift", source);
// Precompile
logger.info(`Processing ${path.join(p.path + r)}`);
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
let c: FuncCompilationResult;
try {
const stdlibPath = path.resolve(
__dirname,
"..",
"stdlib",
"stdlib.fc",
);
const stdlib = fs.readFileSync(stdlibPath, "utf-8");
const code = fs.readFileSync(p.path + r, "utf-8");
c = await funcCompile({
entries: [stdlibPath, p.path + r],
sources: [
{
path: stdlibPath,
content: stdlib,
},
{
path: p.path + r,
content: code,
},
],
logger: logger,
});
if (!c.ok) {
logger.error(c.log);
throw new Error(
`FunC compilation failed for ${path.join(p.path, r)}`,
);
}
} catch (e) {
logger.error(e as Error);
logger.error(`Failed for ${path.join(p.path, r)}`);
throw e;
}
fs.writeFileSync(p.path + r + ".fift", c.fift!);
fs.writeFileSync(p.path + r + ".cell", c.output!);

// Cell -> Fift decompiler
const source = decompileAll({ src: c.output! });
fs.writeFileSync(p.path + r + ".rev.fift", source);
}
}
} catch (error) {
logger.error(error as Error);
process.exit(1);
}
})();
2 changes: 1 addition & 1 deletion src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createVirtualFileSystem } from "./vfs/createVirtualFileSystem";
export async function run(args: {
config: Config;
files: { [key: string]: string };
logger?: Logger | null | undefined;
logger?: Logger;
}) {
// Verify config
const config = verifyConfig(args.config);
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Logger {
if (message instanceof Error) {
message = message.stack || message.message;
} else {
message = "" + message.toString();
message = message.toString();
}

if (level > this.level) return;
Expand Down
9 changes: 8 additions & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ export async function run(args: {
}) {
const configWithRootPath = await loadConfig(args.fileName, args.configPath);
if (!configWithRootPath) {
return { ok: false, error: [new Error("Unable to load config")] };
return {
ok: false,
error: [
new Error(
`Unable to load config from path: ${args.configPath}`,
),
],
};
}

const logger = new Logger(args.suppressLog ? LogLevel.NONE : LogLevel.INFO);
Expand Down
20 changes: 10 additions & 10 deletions src/pipeline/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function build(args: {
config: ConfigProject;
project: VirtualFileSystem;
stdlib: string | VirtualFileSystem;
logger?: Logger | null | undefined;
logger?: Logger;
}): Promise<{ ok: boolean; error: TactErrorCollection[] }> {
const { config, project } = args;
const stdlib =
Expand Down Expand Up @@ -112,7 +112,7 @@ export async function build(args: {
let codeEntrypoint: string;

// Compiling contract to func
logger.info(" > " + contract + ": tact compiler");
logger.info(` > ${contract}: tact compiler`);
let abi: string;
try {
const res = await compile(
Expand Down Expand Up @@ -336,10 +336,10 @@ export async function build(args: {
bindingsServer,
);
} catch (e) {
const message = "Bindings compiler crashed";
logger.error(message);
logger.error(e as Error);
errorMessages.push(new Error(message));
const error = e as Error;
error.message = `Bindings compiler crashed, ${error.message}`;
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
logger.error(error);
errorMessages.push(error);
return { ok: false, error: errorMessages };
}
}
Expand All @@ -356,10 +356,10 @@ export async function build(args: {
);
project.writeFile(pathBindings, report);
} catch (e) {
const message = "Report generation crashed";
logger.error(message);
logger.error(e as Error);
errorMessages.push(new Error(message));
const error = e as Error;
error.message = `Report generation crashed, ${error.message}`;
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
logger.error(error);
errorMessages.push(error);
return { ok: false, error: errorMessages };
}
}
Expand Down