Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp (C++)

Code before:
            // We intentionally don't use a const reference here because we modify
            // the profile stub by giving it a guid so we can call _FindMatchingProfile
            for (auto& profileStub : fullFile[JsonKey(ProfilesKey)])
            {
                if (profileStub.isMember(JsonKey(UpdatesKey)))
                {
                    // This stub is meant to be a modification to an existing profile,
                    // try to find the matching profile
                    profileStub[JsonKey(GuidKey)] = profileStub[JsonKey(UpdatesKey)];
                    auto matchingProfile = _FindMatchingProfile(profileStub);
                    if (matchingProfile)
                    {
                        // We found a matching profile, create a child of it and put the modifications there
                        // (we add a new inheritance layer)
                        auto childImpl{ matchingProfile->CreateChild() };
                        childImpl->LayerJson(profileStub);
                        childImpl->Origin(OriginTag::Fragment);

                        // replace parent in _profiles with child
                        _allProfiles.SetAt(_FindMatchingProfileIndex(matchingProfile->ToJson()).value(), *childImpl);
                    }
                }
                else
                {
                    // This is a new profile, check that it meets our minimum requirements first
                    // (it must have at least a name)
                    if (profileStub.isMember(JsonKey(NameKey)))
                    {
                        auto newProfile = Profile::FromJson(profileStub);
                        // Make sure to give the new profile a source, then we add it to our list of profiles
                        // We don't make modifications to the user's settings file yet, that will happen when
                        // _AppendDynamicProfilesToUserSettings() is called later
                        newProfile->Source(source);
                        newProfile->Origin(OriginTag::Fragment);
                        _allProfiles.Append(*newProfile);
                    }
                }
            }
        }

        if (fullFile.isMember(JsonKey(SchemesKey)))
        {
            // Now we separately get each stub that adds a color scheme
            for (const auto& schemeStub : fullFile[JsonKey(SchemesKey)])
            {
                if (_FindMatchingColorScheme(schemeStub))
                {
                    // We do not allow modifications to existing color schemes
                }
                else
                {

Review comment (suggestion):
Note, we are deliberately choosing _not_ to append a warning here because this is an issue with the fragment, which is unlikely to be the fault of the user

Code after:
            // We intentionally don't use a const reference here because we modify
            // the profile stub by giving it a guid so we can call _FindMatchingProfile
            for (auto& profileStub : fullFile[JsonKey(ProfilesKey)])
            {
                if (profileStub.isMember(JsonKey(UpdatesKey)))
                {
                    // This stub is meant to be a modification to an existing profile,
                    // try to find the matching profile
                    profileStub[JsonKey(GuidKey)] = profileStub[JsonKey(UpdatesKey)];
                    auto matchingProfile = _FindMatchingProfile(profileStub);
                    if (matchingProfile)
                    {
                        try
                        {
                            // We found a matching profile, create a child of it and put the modifications there
                            // (we add a new inheritance layer)
                            auto childImpl{ matchingProfile->CreateChild() };
                            childImpl->LayerJson(profileStub);
                            childImpl->Origin(OriginTag::Fragment);

                            // replace parent in _profiles with child
                            _allProfiles.SetAt(_FindMatchingProfileIndex(matchingProfile->ToJson()).value(), *childImpl);
                        }
                        catch (...)
                        {
                        }
                    }
                }
                else
                {
                    // This is a new profile, check that it meets our minimum requirements first
                    // (it must have at least a name)
                    if (profileStub.isMember(JsonKey(NameKey)))
                    {
                        try
                        {
                            auto newProfile = Profile::FromJson(profileStub);
                            // Make sure to give the new profile a source, then we add it to our list of profiles
                            // We don't make modifications to the user's settings file yet, that will happen when
                            // _AppendDynamicProfilesToUserSettings() is called later
                            newProfile->Source(source);
                            newProfile->Origin(OriginTag::Fragment);
                            _allProfiles.Append(*newProfile);
                        }
                        catch (...)
                        {
                        }
                    }
                }
            }
        }