Skip to content

Commit

Permalink
fix: IgnoreMissingProperties should ignore objects
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Fisher <matt.fisher@fermyon.com>
  • Loading branch information
bacongobbler committed Oct 12, 2022
1 parent 5605d7c commit cca52d5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Tomlyn.Tests/ModelTests/ReflectionModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ public void TestModelWithFixedList()
public void TestModelWithMissingProperties()
{
var input = @"values = ['1', '2', '3']
some_thing_that_doesnt_exist = true";
some_thing_that_doesnt_exist = true
[object_that_doesnt_exist]
required = true";

StandardTests.DisplayHeader("input");
Console.WriteLine(input);
Expand Down
7 changes: 6 additions & 1 deletion src/Tomlyn/Model/Accessors/DictionaryDynamicAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ public override bool TryCreateAndSetDefaultPropertyValue(SourceSpan span, object
errorMessage = $"Unexpected error when creating object for property {name} on object type {TargetType.FullName}. Reason: {ex.Message}";
}

Context.Diagnostics.Error(span, errorMessage);
// If configured to ignore missing properties on the target type,
// return false to indicate it is missing but don't set an error
if (!Context.IgnoreMissingProperties)
{
Context.Diagnostics.Error(span, errorMessage);
}
return false;
}

Expand Down
7 changes: 6 additions & 1 deletion src/Tomlyn/Model/Accessors/StandardObjectDynamicAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,12 @@ public override bool TryCreateAndSetDefaultPropertyValue(SourceSpan span, object
errorMessage = $"Unexpected error when creating object for property {name} on object type {TargetType.FullName}. Reason: {ex.Message}";
}

Context.Diagnostics.Error(span, errorMessage);
// If configured to ignore missing properties on the target type,
// return false to indicate it is missing but don't set an error
if (!Context.IgnoreMissingProperties)
{
Context.Diagnostics.Error(span, errorMessage);
}
return false;
}
}

0 comments on commit cca52d5

Please sign in to comment.