Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to heal settings files damaged by #9962 #10143

Merged
2 commits merged into from
May 21, 2021
Merged

Conversation

DHowett
Copy link
Member

@DHowett DHowett commented May 20, 2021

The bug that caused #9962 resulted in folks getting profiles written to
their settings that didn't contain any identifying information (name or
guid), sometimes multiple times.

These profiles look (somewhat) like this:

{ "colorScheme": "Campbell" },
{},

An empty profile serves no purpose -- it shows up in the list as being
named "Default", and it only launches CMD (unless the commandline is the
thing that the user successfully changed.)

We can heal the settings file by simply ignoring those profiles that
have no identifying information (a guid or a name that can be
converted into a guid).

Validation

I created a number of profiles that fit this format and made sure that
they were ignored on load and destroyed on save.

PR Checklist

  • Closes an annoyance we discovered after 9962.

The bug that caused #9962 resulted in folks getting profiles written to
their settings that didn't contain any identifying information (name or
guid), sometimes multiple times.

These profiles look (somewhat) like this:

```json
{ "colorScheme": "Campbell" },
{},
```

An empty profile serves no purpose -- it shows up in the list as being
named "Default", and it only launches CMD (unless the commandline is the
thing that the user successfully changed.)

We can heal the settings file by simply ignoring those profiles that
have *no identifying information* (a guid or a name that can be
converted into a guid).

Validation
----------
I created a number of profiles that fit this format and made sure that
they were ignored on load and destroyed on save.
static bool _IsValidProfileObject(const Json::Value& profileJson)
{
return profileJson.isMember(&*NameKey.begin(), &*NameKey.end()) || // has a name (can generate a guid)
profileJson.isMember(&*GuidKey.begin(), &*GuidKey.end()); // or has a guid
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frick, I meant to fix this -- this will throw in debug

Comment on lines +806 to +807
return profileJson.isMember(&*NameKey.cbegin(), (&*NameKey.cbegin()) + NameKey.size()) || // has a name (can generate a guid)
profileJson.isMember(&*GuidKey.cbegin(), (&*GuidKey.cbegin()) + GuidKey.size()); // or has a guid
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know, the iterator math is ugly. this is the alternative to creating a copy of the name/guid string views as strings every time we want to check.

This should be in JsonUtils as another "string_view adapter" (like GetValue and SetValue do), but I am not doing this in this PR.

@zadjii-msft zadjii-msft added the Needs-Second It's a PR that needs another sign-off label May 21, 2021
@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label May 21, 2021
@ghost
Copy link

ghost commented May 21, 2021

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 84f6a29 into main May 21, 2021
@ghost ghost deleted the dev/duhowett/yeet_bad_profiles branch May 21, 2021 16:36
DHowett added a commit that referenced this pull request May 24, 2021
The bug that caused #9962 resulted in folks getting profiles written to
their settings that didn't contain any identifying information (name or
guid), sometimes multiple times.

These profiles look (somewhat) like this:

```json
{ "colorScheme": "Campbell" },
{},
```

An empty profile serves no purpose -- it shows up in the list as being
named "Default", and it only launches CMD (unless the commandline is the
thing that the user successfully changed.)

We can heal the settings file by simply ignoring those profiles that
have *no identifying information* (a guid or a name that can be
converted into a guid).

Validation
----------
I created a number of profiles that fit this format and made sure that
they were ignored on load and destroyed on save.

## PR Checklist
* [x] Closes an annoyance we discovered after 9962.

(cherry picked from commit 84f6a29)
@ghost
Copy link

ghost commented May 25, 2021

🎉Windows Terminal v1.8.1444.0 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented May 25, 2021

🎉Windows Terminal Preview v1.9.1445.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoMerge Marked for automatic merge by the bot when requirements are met Needs-Second It's a PR that needs another sign-off
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants