Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds error message to missing file arg #1807

Merged
merged 1 commit into from
May 24, 2024
Merged
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
5 changes: 5 additions & 0 deletions DMCompiler/DMCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@
ForcedWarning("Unimplemented proc & var warnings are currently suppressed");
}

DMPreprocessor preprocessor = Preprocess(settings.Files, settings.MacroDefines);

Check warning on line 54 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Possible null reference argument for parameter 'files' in 'DMPreprocessor? DMCompiler.Preprocess(List<string> files, Dictionary<string, string>? macroDefines)'.

Check warning on line 54 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 54 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'files' in 'DMPreprocessor? DMCompiler.Preprocess(List<string> files, Dictionary<string, string>? macroDefines)'.

Check warning on line 54 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
bool successfulCompile = preprocessor is not null && Compile(preprocessor);

if (successfulCompile) {
//Output file is the first file with the extension changed to .json
string outputFile = Path.ChangeExtension(settings.Files[0], "json");
List<DreamMapJson> maps = ConvertMaps(preprocessor.IncludedMaps);

Check warning on line 60 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 60 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

if (ErrorCount > 0) {
successfulCompile = false;
} else {
var output = SaveJson(maps, preprocessor.IncludedInterface, outputFile);

Check warning on line 65 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Possible null reference argument for parameter 'interfaceFile' in 'string DMCompiler.SaveJson(List<DreamMapJson> maps, string interfaceFile, string outputFile)'.

Check warning on line 65 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'interfaceFile' in 'string DMCompiler.SaveJson(List<DreamMapJson> maps, string interfaceFile, string outputFile)'.
if (ErrorCount > 0) {
successfulCompile = false;
} else {
Expand Down Expand Up @@ -101,6 +101,11 @@
// NB: IncludeFile pushes newly seen files to a stack, so push
// them in reverse order to process them in forward order.
for (var i = files.Count - 1; i >= 0; i--) {
if (!File.Exists(files[i])) {
Console.WriteLine($"'{files[i]}' does not exist");
return null;
}

string includeDir = Path.GetDirectoryName(files[i]);
string fileName = Path.GetFileName(files[i]);

Expand Down Expand Up @@ -133,12 +138,12 @@
if (Settings.DumpPreprocessor) {
//Preprocessing is done twice because the output is used up when dumping it
StringBuilder result = new();
foreach (Token t in Build()) {

Check warning on line 141 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
result.Append(t.Text);
}

string outputDir = Path.GetDirectoryName(Settings.Files[0]);

Check warning on line 145 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 145 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
string outputPath = Path.Combine(outputDir, "preprocessor_dump.dm");

Check warning on line 146 in DMCompiler/DMCompiler.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'path1' in 'string Path.Combine(string path1, string path2)'.

File.WriteAllText(outputPath, result.ToString());
Console.WriteLine($"Preprocessor output dumped to {outputPath}");
Expand Down
Loading