This repository was archived by the owner on Aug 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(compiler): catching unhandled exceptions #77
Open
RossAndersonDev
wants to merge
1
commit into
main
Choose a base branch
from
handle-compiler-exceptions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Bug: -Title- | ||
|
|
||
| <!--- Provide a general summary of the issue in the Title above --> | ||
|
|
||
| ## Expected Behavior | ||
|
|
||
| <!--- Tell us what should happen --> | ||
|
|
||
| ## Current Behavior | ||
|
|
||
| <!--- Tell us what happens instead of the expected behavior --> | ||
|
|
||
| ## Steps to Reproduce | ||
|
|
||
| <!--- Provide a unit test and/or a set of steps to reproduce this bug--> | ||
|
|
||
| - [ ] Unit test provided | ||
|
|
||
| ### Steps | ||
|
|
||
| 1. | ||
|
|
||
| 2. | ||
|
|
||
| 3. | ||
|
|
||
| ## Possible Solution | ||
|
|
||
| <!--- Not obligatory, but suggest a fix/reason for the bug, --> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| namespace Thrift.Net.Compiler | ||||||
| namespace Thrift.Net.Compiler | ||||||
| { | ||||||
| using System; | ||||||
| using System.CommandLine; | ||||||
|
|
@@ -58,50 +58,62 @@ public class Program | |||||
| /// </returns> | ||||||
| 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) | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe worth extracting this code out to a method, just to keep the |
||||||
| { | ||||||
| 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}"); | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could set the |
||||||
| console.Out.Write($"We welcome contributions, so please feel free to create a PR to resolve the issue.{Environment.NewLine}"); | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
After reading it I just figure we had too many "pleases" in there 😸 |
||||||
| 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) | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can automatically set a few properties like labels by adding some yaml frontmatter to the file. Something like this:
There's some details about it here: https://docs.github.com/en/free-pro-team@latest/github/building-a-strong-community/manually-creating-a-single-issue-template-for-your-repository
Should we maybe call the file
bug_template.mdas well?Can I get you to move this to a
.githubdirectory as well, just so we put anything related to automating GitHub in the one place?