Skip to content

Commit b249296

Browse files
committed
Better error reporting when Node.js is not installed when generating TypeScript files.
1 parent 44fd93c commit b249296

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

src/Common/Log.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ public class Log
1414
public static string ErrorLogFilePath = ErrorLogFile;
1515
public static string MessageLogFilePath = MessageLogFile;
1616

17-
public static void Exception(Exception e, string message)
17+
public static void Exception(Exception e, string message, bool isSevere = true)
1818
{
19-
WriteToFile(message + Environment.NewLine + e.ToString(), ErrorLogFilePath);
19+
var text = message + Environment.NewLine + e.ToString();
20+
Exception(text, isSevere);
2021
}
2122

22-
public static void Exception(string message)
23+
public static void Exception(string message, bool isSevere = true)
2324
{
24-
Write(message, ConsoleColor.Red);
25+
Write(message, isSevere ? ConsoleColor.Red : ConsoleColor.Yellow);
2526
WriteToFile(message, ErrorLogFilePath);
2627
}
2728

src/HtmlGenerator/Pass1-Generation/TypeScriptSupport.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.IO;
45
using System.Linq;
56
using System.Text;
@@ -50,7 +51,15 @@ public void Generate(IEnumerable<string> typeScriptFiles)
5051
libFile = Path.Combine(Common.Paths.BaseAppFolder, "TypeScriptSupport", "lib.d.ts");
5152
}
5253

53-
GenerateCore(list, libFile);
54+
try
55+
{
56+
GenerateCore(list, libFile);
57+
}
58+
catch (Exception ex)
59+
{
60+
Log.Exception(ex, "Error when generating TypeScript files");
61+
return;
62+
}
5463

5564
ProjectGenerator.GenerateReferencesDataFilesToAssembly(
5665
Paths.SolutionDestinationFolder,
@@ -81,7 +90,19 @@ private void GenerateCore(IEnumerable<string> fileNames, string libFile)
8190
File.WriteAllText(argumentsJson, json);
8291

8392
var analyzerJs = Path.Combine(Common.Paths.BaseAppFolder, @"TypeScriptSupport\analyzer.js");
84-
var result = new ProcessLaunchService().RunAndRedirectOutput("node", string.Format("\"{0}\" {1}", analyzerJs, argumentsJson));
93+
var arguments = string.Format("\"{0}\" {1}", analyzerJs, argumentsJson);
94+
95+
ProcessLaunchService.ProcessRunResult result;
96+
try
97+
{
98+
result = new ProcessLaunchService().RunAndRedirectOutput("node", arguments);
99+
}
100+
catch (Win32Exception)
101+
{
102+
Log.Write("Warning: Node.js is required to generate TypeScript files. Skipping generation. Download Node.js from https://nodejs.org.", ConsoleColor.Yellow);
103+
Log.Exception("Node.js is not installed.");
104+
return;
105+
}
85106

86107
foreach (var file in Directory.GetFiles(output))
87108
{

src/HtmlGenerator/Utilities/FirstChanceExceptionHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static void HandleFirstChanceException(object sender, FirstChanceExceptio
125125
}
126126
}
127127

128-
Log.Exception(ex, message);
128+
Log.Exception(ex, message, isSevere: false);
129129
}
130130
finally
131131
{

0 commit comments

Comments
 (0)