diff --git a/issue_template.md b/issue_template.md
new file mode 100644
index 0000000..f200ff0
--- /dev/null
+++ b/issue_template.md
@@ -0,0 +1,29 @@
+# Bug:
+
+
+
+## Expected Behavior
+
+
+
+## Current Behavior
+
+
+
+## Steps to Reproduce
+
+
+
+- [ ] Unit test provided
+
+### Steps
+
+1.
+
+2.
+
+3.
+
+## Possible Solution
+
+
diff --git a/src/Thrift.Net.Compiler/ExitCode.cs b/src/Thrift.Net.Compiler/ExitCode.cs
index 08cf742..e11afa2 100644
--- a/src/Thrift.Net.Compiler/ExitCode.cs
+++ b/src/Thrift.Net.Compiler/ExitCode.cs
@@ -19,5 +19,10 @@ public enum ExitCode
/// Compilation has failed because of one or more errors.
///
CompilationFailed = 2,
+
+ ///
+ /// Compilation has failed because of an unhandled exception.
+ ///
+ UnhandledException = 3,
}
}
\ No newline at end of file
diff --git a/src/Thrift.Net.Compiler/Program.cs b/src/Thrift.Net.Compiler/Program.cs
index aebba3d..dd4d213 100644
--- a/src/Thrift.Net.Compiler/Program.cs
+++ b/src/Thrift.Net.Compiler/Program.cs
@@ -1,4 +1,4 @@
-namespace Thrift.Net.Compiler
+namespace Thrift.Net.Compiler
{
using System;
using System.CommandLine;
@@ -58,50 +58,62 @@ public class Program
///
public static int Main(FileInfo input, DirectoryInfo outputDirectory, IConsole console = null)
{
- if (!input.Exists)
+ try
{
- console.Error.Write($"The specified input file '{input.Name}' could not be found.{Environment.NewLine}");
- return (int)ExitCode.InputFileNotFound;
- }
+ if (!input.Exists)
+ {
+ console.Error.Write($"The specified input file '{input.Name}' could not be found.{Environment.NewLine}");
+ return (int)ExitCode.InputFileNotFound;
+ }
- if (!outputDirectory.Exists)
- {
- outputDirectory.Create();
- }
+ if (!outputDirectory.Exists)
+ {
+ outputDirectory.Create();
+ }
- console.Out.Write($"Starting compilation of {input.Name}{Environment.NewLine}");
+ console.Out.Write($"Starting compilation of {input.Name}{Environment.NewLine}");
- var thriftFile = FileProvider.Create(
- new DirectoryInfo(Directory.GetCurrentDirectory()),
- input,
- outputDirectory);
+ var thriftFile = FileProvider.Create(
+ new DirectoryInfo(Directory.GetCurrentDirectory()),
+ input,
+ outputDirectory);
- using (var stream = input.OpenRead())
- {
- var result = Compiler.Compile(stream);
+ using (var stream = input.OpenRead())
+ {
+ var result = Compiler.Compile(stream);
- OutputCompilationSummary(console, result);
+ OutputCompilationSummary(console, result);
- // TODO: Pull message formatting out to its own object.
- foreach (var message in result.Messages.OrderBy(message => message.LineNumber))
- {
- console.Out.Write($"{thriftFile.RelativePath}({message.LineNumber},{message.StartPosition}-{message.EndPosition}): {message.MessageType} {message.FormattedMessageId}: {message.Message} [{input.FullName}]{Environment.NewLine}");
- }
+ // TODO: Pull message formatting out to its own object.
+ foreach (var message in result.Messages.OrderBy(message => message.LineNumber))
+ {
+ console.Out.Write($"{thriftFile.RelativePath}({message.LineNumber},{message.StartPosition}-{message.EndPosition}): {message.MessageType} {message.FormattedMessageId}: {message.Message} [{input.FullName}]{Environment.NewLine}");
+ }
- if (result.HasErrors)
- {
- return (int)ExitCode.CompilationFailed;
- }
+ if (result.HasErrors)
+ {
+ return (int)ExitCode.CompilationFailed;
+ }
- if (result.Document.ContainsDefinitions)
- {
- var generatedCode = DocumentGenerator.Generate(result.Document);
+ if (result.Document.ContainsDefinitions)
+ {
+ var generatedCode = DocumentGenerator.Generate(result.Document);
- FileWriter.Write(thriftFile, generatedCode);
+ FileWriter.Write(thriftFile, generatedCode);
+ }
}
- }
- return (int)ExitCode.Success;
+ return (int)ExitCode.Success;
+ }
+ catch (Exception exception)
+ {
+ console.Out.Write($"Error: {exception}{Environment.NewLine}{Environment.NewLine}");
+ console.Out.Write($"Thrift.Net has encountered an error. This is a problem with the compiler and not caused by your code.{Environment.NewLine}");
+ console.Out.Write($"Please help us to resolve this by reporting a new issue here: https://github.com/adamconnelly/Thrift.Net/issues/new?template=issue_template.md. {Environment.NewLine} {Environment.NewLine}");
+ console.Out.Write($"We welcome contributions, so please feel free to create a PR to resolve the issue.{Environment.NewLine}");
+ console.Out.Write($"You can find out how to contribute here: https://github.com/adamconnelly/Thrift.Net/blob/main/docs/CONTRIBUTING.md. {Environment.NewLine}");
+ return (int)ExitCode.UnhandledException;
+ }
}
private static void OutputCompilationSummary(IConsole console, CompilationResult result)