Skip to content

Commit

Permalink
fix error when chest options are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
Pathoschild committed Dec 21, 2022
1 parent b8323d3 commit 83fe726
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChestsAnywhere/docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[← back to readme](README.md)

# Release notes
## Upcoming release
* Fixed error when another mod sets invalid chest options.

## 1.22.4
Released 30 October 2022 for SMAPI 3.14.0 or later.

Expand Down
16 changes: 13 additions & 3 deletions Common/ModDataDictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ internal static class ModDataDictionaryExtensions
[return: NotNullIfNotNull("defaultValue")]
public static T? ReadField<T>(this ModDataDictionary data, string key, Func<string, T> parse, T? defaultValue = default)
{
return data.TryGetValue(key, out string rawValue)
? parse(rawValue)
: defaultValue;
if (data.TryGetValue(key, out string rawValue))
{
try
{
return parse(rawValue);
}
catch
{
// if the format is invalid, fallback to the default value
}
}

return defaultValue;
}

/// <summary>Read a field from the mod data dictionary.</summary>
Expand Down

0 comments on commit 83fe726

Please sign in to comment.