tact-lang / tact

Tact compiler main repository
https://tact-lang.org
MIT License
394 stars 110 forks source link

Throw `TactCompilationError` instead `Error` when possible #645

Closed byakuren-hijiri closed 3 months ago

byakuren-hijiri commented 3 months ago

Tact compiler throws exceptions when compilation errors occur. Typically, it uses throwCompilationError for this.

This enables the third-party tools to understand the reason of the exception by inspecting the error stacktrace, e.g.:

  static isCompilationError(stack: string | undefined): boolean {
    return stack !== undefined && stack.includes("at throwCompilationError");
  }

The problem is that in some cases we use throw new Error when compilation error occurs. For example, when an unresolved import appears:

https://github.com/tact-lang/tact/blob/2524aae05b558deaab3ce01086aefc21d65373c8/src/imports/resolveImports.ts#L50

The idea is to examine all the cases when we throw and to replace them with throwCompilationError or throwInternalCompilerError if possible.

This will be helpful for the tooling and will provide a more unified internal API, fostering debugging of Tact.

anton-trunov commented 3 months ago

This is definitely where we are going to. There is on detail, though. We should provide more info and not just throw TactCompilationError but differentiate between error kinds: parse errors, type errors, etc.