nujan-io / nujan-ide

Web IDE, powered by Nujan, is your ultimate browser-based IDE designed to simplify the journey of writing, testing, compiling, deploying, and interacting with smart contracts on TON. Write smart contracts from anywhere, No setups, no downloads, just pure convenience and versatility.
https://ide.nujan.io
Other
98 stars 10 forks source link

Display Tact compilation errors #19

Open novusnota opened 3 months ago

novusnota commented 3 months ago

Observed behaviour

Upon compilation error, user sees a cryptic "Error while building" message in the log output. And that's it, no details.

Expected behavior or possible solutions

Tact compiler provides details on compilation errors and it would be nice to see them in the log output even if the stack trace is truncated.

rahulyadav-57 commented 2 months ago

The Tact compiler does not throw an errors in some cases; instead, it logs them to the console, as detailed in issue https://github.com/tact-lang/tact/issues/262. As a temporary workaround, I have implemented a method to capture console.error outputs and display them in the Nujan log.

Please notify me if there are any issues with errors not being logged properly.

novusnota commented 1 month ago

@rahulyadav-57 I think this shall be re-opened, as dump() and emit() are not logged anymore after updating to Tact 1.3.0. Probably, we need to revert the temporary workaround you made before

rahulyadav-57 commented 1 month ago

Hi @novusnota, I tested it and it works for me; could you help me to reproduce it?

novusnota commented 1 month ago

Sure @rahulyadav-57, it works in init() and receive(), but doesn't work in (off-chain) getter functions get fun X()

rahulyadav-57 commented 1 month ago

@novusnota Instead of intercepting the console which I did previously, which captures everything globally, I propose an alternative solution. We could replace the logger.js file after npm install in Nujan at node_modules/@tact-lang/compiler/dist/ with a custom logger that can dispatch events which can be capture by Nujan logger. This approach might provide more targeted and manageable event handling.

Something like

const disptachEvent = (type, args) => {
    const tactEvent = new CustomEvent("tactLogger", {
        detail: { data: args, type},
    });
    document.dispatchEvent(tactEvent);
    console[type](args);
}

exports.consoleLogger = {
    log: (message) => disptachEvent('log', message),
    error: (message) => disptachEvent('log', message),
};

What are your thoughts @anton-trunov on this?

anton-trunov commented 1 month ago

@rahulyadav-57 I think we should fix it in Tact itself

anton-trunov commented 1 month ago

In general I would strongly discourage patching things up. Please don't shy away from fixing things in the compiler or any other tool, i.e. where it's relevant

rahulyadav-57 commented 1 month ago

I agree with you. But for the current or older version of Tact, how should we proceed?

anton-trunov commented 1 month ago

We can fix the current version of Tact, release it as v1.3.1 and require it should be the minimal Tact version for Nujan

rahulyadav-57 commented 1 month ago

Yes, that solution would resolve the issue. I'll make the changes and raise a PR. However, in Nujan, we plan to support multiple versions of Tact, including older versions as well.