JohnMasen/ChakraCore.NET

Retrieving line and column of the error from a script

Opened this issue · 1 comments

Is it possible to retrieve the line and column information of the error thrown from within script? Right now the JavaScriptException only has the error message and stacktrace from the library.

Chakracore does not tell the caller the line and column unless the engine is in "debug mode". the debugging feature is implemented in the chakracore.net.core package and a VS code plugin is built base on top of that.
If you simply want the line number, suggest implement your own debug adapter.
all you need to do is implement IDebugAdapter interface.

for OnAsyncBreak,OnBreakPoint,OnException,OnStepComplete, you can simply call the debuggingService.Step(JavaScriptDiagStepType.JsDiagStepTypeContinue); at the end of event handler, this tells the engine to continue code execution or throw an error to caller (only applies to OnException)
Here's the implementation in VSCodeAdapter

public void Init(IRuntimeDebuggingService debuggingService)
        {
            this.debuggingService = debuggingService;
            debuggingService.OnAsyncBreak += DebuggingService_OnAsyncBreak;
            debuggingService.OnBreakPoint += DebuggingService_OnBreakPoint;
            debuggingService.OnDebugEvent += DebuggingService_OnDebugEvent;
            debuggingService.OnEngineReady += DebuggingService_OnEngineReady;
            debuggingService.OnException += DebuggingService_OnException;
            debuggingService.OnScriptLoad += DebuggingService_OnScriptLoad;
            debuggingService.OnStepComplete += DebuggingService_OnStepComplete;
            debuggingService.StartDebug();
        }