Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions issue_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Bug: -Title-

Copy link
Copy Markdown
Owner

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:

---
name: Bug
about: Use this template for reporting bugs in Thrift.Net.
labels: "type/bug"
---

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.md as well?

Can I get you to move this to a .github directory as well, just so we put anything related to automating GitHub in the one place?


<!--- 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, -->
5 changes: 5 additions & 0 deletions src/Thrift.Net.Compiler/ExitCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ public enum ExitCode
/// Compilation has failed because of one or more errors.
/// </summary>
CompilationFailed = 2,

/// <summary>
/// Compilation has failed because of an unhandled exception.
/// </summary>
UnhandledException = 3,
}
}
78 changes: 45 additions & 33 deletions src/Thrift.Net.Compiler/Program.cs
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;
Expand Down Expand Up @@ -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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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 Main() method fairly simple?

{
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}");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could set the component/compiler label via a query string parameter here? Like you say, once the template's in place it'll be easier to try that out.

console.Out.Write($"We welcome contributions, so please feel free to create a PR to resolve the issue.{Environment.NewLine}");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.Out.Write($"We welcome contributions, so please feel free to create a PR to resolve the issue.{Environment.NewLine}");
console.Out.Write($"We welcome contributions, so feel free to create a PR to resolve the issue.{Environment.NewLine}");

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)
Expand Down