mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 09:06:14 +02:00
pastojs: nodejs js exception handling
git-svn-id: trunk@40126 -
This commit is contained in:
parent
5f43eb5baa
commit
4d69aebf18
@ -305,6 +305,9 @@ type
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
procedure HandleUnknownException(E: Exception);
|
procedure HandleUnknownException(E: Exception);
|
||||||
procedure HandleException(E: Exception);
|
procedure HandleException(E: Exception);
|
||||||
|
{$IFDEF Pas2js}
|
||||||
|
procedure HandleJSException(Msg: string; E: jsvalue);
|
||||||
|
{$ENDIF}
|
||||||
procedure DoLogMsgAtEl(MsgType: TMessageType; const Msg: string;
|
procedure DoLogMsgAtEl(MsgType: TMessageType; const Msg: string;
|
||||||
MsgNumber: integer; El: TPasElement);
|
MsgNumber: integer; El: TPasElement);
|
||||||
procedure RaiseInternalError(id: TMaxPrecInt; Msg: string);
|
procedure RaiseInternalError(id: TMaxPrecInt; Msg: string);
|
||||||
@ -489,6 +492,9 @@ type
|
|||||||
procedure InitParamMacros;
|
procedure InitParamMacros;
|
||||||
procedure ClearDefines;
|
procedure ClearDefines;
|
||||||
procedure RaiseInternalError(id: TMaxPrecInt; Msg: string);
|
procedure RaiseInternalError(id: TMaxPrecInt; Msg: string);
|
||||||
|
{$IFDEF Pas2js}
|
||||||
|
procedure HandleJSException(Msg: string; E: jsvalue; TerminateInternal: boolean = true);
|
||||||
|
{$ENDIF}
|
||||||
function GetExitCode: Longint; virtual;
|
function GetExitCode: Longint; virtual;
|
||||||
procedure SetExitCode(Value: Longint); virtual;
|
procedure SetExitCode(Value: Longint); virtual;
|
||||||
public
|
public
|
||||||
@ -1224,6 +1230,13 @@ begin
|
|||||||
HandleUnknownException(E);
|
HandleUnknownException(E);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$IFDEF Pas2js}
|
||||||
|
procedure TPas2jsCompilerFile.HandleJSException(Msg: string; E: jsvalue);
|
||||||
|
begin
|
||||||
|
Compiler.HandleJSException(Msg,E,true);
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
procedure TPas2jsCompilerFile.DoLogMsgAtEl(MsgType: TMessageType;
|
procedure TPas2jsCompilerFile.DoLogMsgAtEl(MsgType: TMessageType;
|
||||||
const Msg: string; MsgNumber: integer; El: TPasElement);
|
const Msg: string; MsgNumber: integer; El: TPasElement);
|
||||||
var
|
var
|
||||||
@ -1293,6 +1306,11 @@ begin
|
|||||||
raise;
|
raise;
|
||||||
on E: Exception do
|
on E: Exception do
|
||||||
HandleException(E);
|
HandleException(E);
|
||||||
|
{$IFDEF pas2js}
|
||||||
|
else
|
||||||
|
HandleJSException('[20181031190529] TPas2jsCompilerFile.ReaderFinished File="'+PasFilename+'"',
|
||||||
|
JSExceptValue);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1403,6 +1421,9 @@ begin
|
|||||||
raise;
|
raise;
|
||||||
on E: Exception do
|
on E: Exception do
|
||||||
HandleException(E);
|
HandleException(E);
|
||||||
|
{$IFDEF pas2js}
|
||||||
|
else HandleJSException('[20181031190536] TPas2jsCompilerFile.OpenFile "'+aFilename+'"',JSExceptValue);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1446,6 +1467,11 @@ begin
|
|||||||
raise;
|
raise;
|
||||||
on E: Exception do
|
on E: Exception do
|
||||||
HandleException(E);
|
HandleException(E);
|
||||||
|
{$IFDEF pas2js}
|
||||||
|
else
|
||||||
|
HandleJSException('[20181031190541] TPas2jsCompilerFile.ReadUnit File="'+PasFilename+'"',
|
||||||
|
JSExceptValue);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
if FReaderState=prsReading then
|
if FReaderState=prsReading then
|
||||||
FReaderState:=prsError;
|
FReaderState:=prsError;
|
||||||
@ -1486,6 +1512,11 @@ begin
|
|||||||
raise;
|
raise;
|
||||||
on E: Exception do
|
on E: Exception do
|
||||||
HandleException(E);
|
HandleException(E);
|
||||||
|
{$IFDEF pas2js}
|
||||||
|
else
|
||||||
|
HandleJSException('[20181031190545] TPas2jsCompilerFile.ReadContinue File="'+PasFilename+'"',
|
||||||
|
JSExceptValue);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
if FReaderState=prsReading then
|
if FReaderState=prsReading then
|
||||||
FReaderState:=prsError;
|
FReaderState:=prsError;
|
||||||
@ -1532,6 +1563,11 @@ begin
|
|||||||
raise;
|
raise;
|
||||||
on E: Exception do
|
on E: Exception do
|
||||||
HandleException(E);
|
HandleException(E);
|
||||||
|
{$IFDEF pas2js}
|
||||||
|
else
|
||||||
|
HandleJSException('[20181031190549] TPas2jsCompilerFile.CreateJS File="'+PasFilename+'"',
|
||||||
|
JSExceptValue);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2516,7 +2552,10 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Log.LogPlain('[20180204193420] Error while creating JavaScript "'+FileCache.FormatPath(DestFilename)+'": '+E.Message);
|
Log.LogPlain('[20180204193420] Error while creating JavaScript "'+FileCache.FormatPath(DestFilename)+'": '+E.Message);
|
||||||
Terminate(ExitCodeErrorInternal);
|
Terminate(ExitCodeErrorInternal);
|
||||||
end;
|
end
|
||||||
|
{$IFDEF Pas2js}
|
||||||
|
else HandleJSException('[20181031190520] TPas2jsCompiler.WriteJSFiles Error while creating JavaScript',JSExceptValue);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if aFile.IsMainFile and (TargetPlatform=PlatformNodeJS) then
|
if aFile.IsMainFile and (TargetPlatform=PlatformNodeJS) then
|
||||||
@ -2621,7 +2660,10 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Log.LogMsg(nUnableToWriteFile,[QuoteStr(FileCache.FormatPath(DestFilename))]);
|
Log.LogMsg(nUnableToWriteFile,[QuoteStr(FileCache.FormatPath(DestFilename))]);
|
||||||
Terminate(ExitCodeWriteError);
|
Terminate(ExitCodeWriteError);
|
||||||
end;
|
end
|
||||||
|
{$IFDEF Pas2js}
|
||||||
|
else HandleJSException('[20181031190637] TPas2jsCompiler.WriteJSFiles',JSExceptValue,true);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// write source map
|
// write source map
|
||||||
@ -2663,7 +2705,10 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Log.LogMsg(nUnableToWriteFile,[QuoteStr(FileCache.FormatPath(MapFilename))]);
|
Log.LogMsg(nUnableToWriteFile,[QuoteStr(FileCache.FormatPath(MapFilename))]);
|
||||||
Terminate(ExitCodeWriteError);
|
Terminate(ExitCodeWriteError);
|
||||||
end;
|
end
|
||||||
|
{$IFDEF Pas2js}
|
||||||
|
else HandleJSException('[20181031190737] TPas2jsCompiler.WriteJSFiles',JSExceptValue);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -2723,6 +2768,32 @@ begin
|
|||||||
raise Exception.Create(Msg);
|
raise Exception.Create(Msg);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$IFDEF Pas2js}
|
||||||
|
procedure TPas2jsCompiler.HandleJSException(Msg: string; E: jsvalue;
|
||||||
|
TerminateInternal: boolean);
|
||||||
|
var
|
||||||
|
obj: JS.TJSObject;
|
||||||
|
begin
|
||||||
|
if isObject(E) then
|
||||||
|
begin
|
||||||
|
obj:=js.TJSObject(E);
|
||||||
|
if isExt(obj,TJSError) then
|
||||||
|
begin
|
||||||
|
{AllowWriteln}
|
||||||
|
if obj['stack'] then
|
||||||
|
writeln(obj['stack']);
|
||||||
|
{AllowWriteln-}
|
||||||
|
Log.Log(mtFatal,Msg+': '+String(obj['message']));
|
||||||
|
end else
|
||||||
|
Log.Log(mtFatal,Msg+': '+String(E));
|
||||||
|
end else begin
|
||||||
|
Log.Log(mtFatal,Msg+': '+String(E));
|
||||||
|
end;
|
||||||
|
if TerminateInternal then
|
||||||
|
Terminate(ExitCodeErrorInternal);
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
function TPas2jsCompiler.GetExitCode: Longint;
|
function TPas2jsCompiler.GetExitCode: Longint;
|
||||||
begin
|
begin
|
||||||
Result:=System.ExitCode;
|
Result:=System.ExitCode;
|
||||||
@ -4003,7 +4074,10 @@ begin
|
|||||||
{$ELSE}
|
{$ELSE}
|
||||||
Log.LogExceptionBackTrace;
|
Log.LogExceptionBackTrace;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end
|
||||||
|
{$IFDEF Pas2js}
|
||||||
|
else HandleJSException('[20181031190818] TPas2jsCompiler.Destroy',JSExceptValue);
|
||||||
|
{$ENDIF}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
FreeStuff;
|
FreeStuff;
|
||||||
@ -4196,6 +4270,9 @@ begin
|
|||||||
if ShowDebug then
|
if ShowDebug then
|
||||||
Log.LogExceptionBackTrace;
|
Log.LogExceptionBackTrace;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF Pas2js}
|
||||||
|
HandleJSException('[20181031190933] TPas2jsCompiler.Run',JSExceptValue,false);
|
||||||
|
{$ENDIF}
|
||||||
raise;
|
raise;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user