Skip to content

Commit

Permalink
Fix deserialization failure message of combined types (#8558)
Browse files Browse the repository at this point in the history
Closes #7690
  • Loading branch information
Don-Vito committed Dec 15, 2020
1 parent a1f42e8 commit da6705c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@
},
"fontWeight": {
"default": "normal",
"description": "Sets the weight (lightness or heaviness of the strokes) for the given font. Possible values:\n -\"thin\"\n -\"extra-light\"\n -\"light\"\n -\"semi-light\"\n -\"normal\" (default)\n -\"medium\"\n -\"semi-bold\"\n -\"bold\"\n -\"extra-bold\"\n -\"black\"\n -\"extra-black\" or the corresponding numeric representation of OpenType font weight.",
"description": "Sets the weight (lightness or heaviness of the strokes) for the given font. Possible values:\n -\"thin\"\n -\"extra-light\"\n -\"light\"\n -\"semi-light\"\n -\"normal\" (default)\n -\"medium\"\n -\"semi-bold\"\n -\"bold\"\n -\"extra-bold\"\n -\"black\"\n -\"extra-black\"\n or the corresponding numeric representation of OpenType font weight.",
"oneOf": [
{
"enum": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ static void _CatchRethrowSerializationExceptionWithLocationInfo(std::string_view
try
{
jsonValueAsString = e.jsonValue.asString();
if (e.jsonValue.isString())
{
jsonValueAsString = fmt::format("\"{}\"", jsonValueAsString);
}
}
catch (...)
{
// discard: we're in the middle of error handling
}

msg = fmt::format(" Have: \"{}\"\n Expected: {}", jsonValueAsString, e.expectedType);
msg = fmt::format(" Have: {}\n Expected: {}", jsonValueAsString, e.expectedType);

auto [l, c] = _LineAndColumnFromPosition(settingsString, e.jsonValue.getOffsetStart());
msg = fmt::format((e.key ? keyedHeader : basicHeader),
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalSettingsModel/JsonUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ namespace Microsoft::Terminal::Settings::Model::JsonUtils
}

DeserializationError e{ json };
e.expectedType = TypeDescription();
e.expectedType = static_cast<const TBase&>(*this).TypeDescription();
throw e;
}

Expand Down Expand Up @@ -572,7 +572,7 @@ namespace Microsoft::Terminal::Settings::Model::JsonUtils
{
// attempt to combine AllClear (explicitly) with anything else
DeserializationError e{ element };
e.expectedType = BaseEnumMapper::TypeDescription();
e.expectedType = static_cast<const TBase&>(*this).TypeDescription();
throw e;
}
value |= newFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ struct ::Microsoft::Terminal::Settings::Model::JsonUtils::ConversionTrait<::winr
pair_type{ "extra-black", static_cast<uint16_t>(950u) },
};

// Override mapping parser to add boolean parsing
// Override mapping parser to add unsigned int parsing
auto FromJson(const Json::Value& json)
{
unsigned int value{ 400 };
Expand Down Expand Up @@ -191,7 +191,10 @@ struct ::Microsoft::Terminal::Settings::Model::JsonUtils::ConversionTrait<::winr
return BaseEnumMapper::CanConvert(json) || json.isUInt();
}

using EnumMapper::TypeDescription;
std::string TypeDescription() const
{
return EnumMapper::TypeDescription() + " or number";
}
};

JSON_ENUM_MAPPER(::winrt::Windows::UI::Xaml::ElementTheme)
Expand Down

0 comments on commit da6705c

Please sign in to comment.