Skip to content

Commit da6705c

Browse files
authored
Fix deserialization failure message of combined types (#8558)
Closes #7690
1 parent a1f42e8 commit da6705c

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

doc/cascadia/profiles.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@
949949
},
950950
"fontWeight": {
951951
"default": "normal",
952-
"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.",
952+
"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.",
953953
"oneOf": [
954954
{
955955
"enum": [

src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ static void _CatchRethrowSerializationExceptionWithLocationInfo(std::string_view
7373
try
7474
{
7575
jsonValueAsString = e.jsonValue.asString();
76+
if (e.jsonValue.isString())
77+
{
78+
jsonValueAsString = fmt::format("\"{}\"", jsonValueAsString);
79+
}
7680
}
7781
catch (...)
7882
{
7983
// discard: we're in the middle of error handling
8084
}
8185

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

8488
auto [l, c] = _LineAndColumnFromPosition(settingsString, e.jsonValue.getOffsetStart());
8589
msg = fmt::format((e.key ? keyedHeader : basicHeader),

src/cascadia/TerminalSettingsModel/JsonUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ namespace Microsoft::Terminal::Settings::Model::JsonUtils
506506
}
507507

508508
DeserializationError e{ json };
509-
e.expectedType = TypeDescription();
509+
e.expectedType = static_cast<const TBase&>(*this).TypeDescription();
510510
throw e;
511511
}
512512

@@ -572,7 +572,7 @@ namespace Microsoft::Terminal::Settings::Model::JsonUtils
572572
{
573573
// attempt to combine AllClear (explicitly) with anything else
574574
DeserializationError e{ element };
575-
e.expectedType = BaseEnumMapper::TypeDescription();
575+
e.expectedType = static_cast<const TBase&>(*this).TypeDescription();
576576
throw e;
577577
}
578578
value |= newFlag;

src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ struct ::Microsoft::Terminal::Settings::Model::JsonUtils::ConversionTrait<::winr
154154
pair_type{ "extra-black", static_cast<uint16_t>(950u) },
155155
};
156156

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

194-
using EnumMapper::TypeDescription;
194+
std::string TypeDescription() const
195+
{
196+
return EnumMapper::TypeDescription() + " or number";
197+
}
195198
};
196199

197200
JSON_ENUM_MAPPER(::winrt::Windows::UI::Xaml::ElementTheme)

0 commit comments

Comments
 (0)