pas2js: catch jswriter exceptions

git-svn-id: trunk@38114 -
This commit is contained in:
Mattias Gaertner 2018-02-04 18:49:06 +00:00
parent d501448c04
commit 17c010b9a3
2 changed files with 20 additions and 4 deletions

View File

@ -1430,12 +1430,14 @@ var
CombinedFileWriter: TPas2JSMapper; CombinedFileWriter: TPas2JSMapper;
SrcFileCount: integer; SrcFileCount: integer;
Seconds: TDateTime; Seconds: TDateTime;
ok: Boolean;
begin begin
if FMainFile<>nil then if FMainFile<>nil then
RaiseInternalError(20170504192137,''); RaiseInternalError(20170504192137,'');
Checked:=nil; Checked:=nil;
CombinedFileWriter:=nil; CombinedFileWriter:=nil;
SrcFileCount:=0; SrcFileCount:=0;
ok:=false;
try try
// load main Pascal file // load main Pascal file
LoadPasFile(FileCache.MainSrcFile,'',FMainFile); LoadPasFile(FileCache.MainSrcFile,'',FMainFile);
@ -1469,10 +1471,11 @@ begin
Log.LogMsgIgnoreFilter(nLinesInFilesCompiled, Log.LogMsgIgnoreFilter(nLinesInFilesCompiled,
[IntToStr(FileCache.ReadLineCounter),IntToStr(SrcFileCount), [IntToStr(FileCache.ReadLineCounter),IntToStr(SrcFileCount),
FormatFloat('0.0',Seconds)]); FormatFloat('0.0',Seconds)]);
ok:=true;
end; end;
finally finally
Checked.Free; Checked.Free;
if ExitCode<>0 then if not Ok then
Log.LogMsgIgnoreFilter(nCompilationAborted,[]); Log.LogMsgIgnoreFilter(nCompilationAborted,[]);
CombinedFileWriter.Free; CombinedFileWriter.Free;
end; end;
@ -1743,7 +1746,14 @@ begin
aJSWriter:=TJSWriter.Create(aFileWriter); aJSWriter:=TJSWriter.Create(aFileWriter);
aJSWriter.Options:=[woUseUTF8,woCompactArrayLiterals,woCompactObjectLiterals,woCompactArguments]; aJSWriter.Options:=[woUseUTF8,woCompactArrayLiterals,woCompactObjectLiterals,woCompactArguments];
aJSWriter.IndentSize:=2; aJSWriter.IndentSize:=2;
aJSWriter.WriteJS(aFile.JSModule); try
aJSWriter.WriteJS(aFile.JSModule);
except
on E: Exception do begin
Log.LogPlain('[20180204193420] Error while creating JavaScript "'+FileCache.FormatPath(DestFilename)+'": '+E.Message);
Terminate(ExitCodeErrorInternal);
end;
end;
if aFile.IsMainFile and (TargetPlatform=PlatformNodeJS) then if aFile.IsMainFile and (TargetPlatform=PlatformNodeJS) then
aFileWriter.WriteFile('rtl.run();'+LineEnding,aFile.PasFilename); aFileWriter.WriteFile('rtl.run();'+LineEnding,aFile.PasFilename);

View File

@ -11,8 +11,8 @@ uses
{$IFDEF UNIX} {$IFDEF UNIX}
cthreads, cwstring, cthreads, cwstring,
{$ENDIF} {$ENDIF}
Pas2jsFileUtils, Classes, SysUtils, CustApp, Classes, SysUtils, CustApp,
Pas2jsCompiler; Pas2jsFileUtils, Pas2jsLogger, Pas2jsCompiler;
Type Type
@ -44,6 +44,12 @@ begin
Compiler.Run(ParamStr(0),GetCurrentDirUTF8,ParamList); Compiler.Run(ParamStr(0),GetCurrentDirUTF8,ParamList);
except except
on E: ECompilerTerminate do ; on E: ECompilerTerminate do ;
on E: Exception do
begin
writeln(E.Message);
if ExitCode=0 then
ExitCode:=ExitCodeErrorInternal;
end;
end; end;
finally finally
ParamList.Free; ParamList.Free;