PowerToys Run crash

Created on 23 Oct 2020  ·  16Comments  ·  Source: microsoft/PowerToys

ℹ Computer information

  • PowerToys version: v23.2
  • PowerToys Utility: PowerToys Run
  • Running PowerToys as Admin: Yes
  • Windows: Windows 10 Pro 64 Bit, latest patch
  • Windows build number: Version 20H2 OS Build: 19042.572

📝

  1. Open PowerToys Settings
  2. Click PowerToys Run

✔️ Expected result

PowerToys Settings should show all settings for PowerToys Run

❌ Actual result

PowerToys Setting Crashes

📝

  1. Use the Keyboard Shortcut for PowerToys Run

✔️ Expected result

PowerToys Run search should appear

❌ Actual result

Nothing Appears

Issue-Bug Product-Settings Resolution-Fix-Committed

All 16 comments

can you share your settings? Zip these up. C:\Users\crutkas\AppData\Local\Microsoft\PowerToys\

{"packaged":false,"startup":true,"enabled":{"ColorPicker":true,"FancyZones":false,"File Explorer":true,"Image Resizer":false,"Keyboard Manager":true,"PowerRename":false,"PowerToys Run":true,"Shortcut Guide":true},"is_elevated":true,"run_elevated":true,"download_updates_automatically":true,"is_admin":true,"theme":"dark","system_theme":"dark","powertoys_version":"v0.23.2"}

@ryanbodrug-microsoft, @crutkas, @enricogior I was able to repro the crash using the settings shared above. The settings.json for PT Run is corrupted. It looks like a memory dump. When the PT Run tab is selected in the navigation menu, it tries to initialize the settings of PT Run and crashes because this file is invalid.

Regarding why it could happen, maybe something went wrong when runner was saving the config, when it was shut down the previous time or when it was created for the first time by the settings process. I was thinking if maybe there was a race condition and PT was shut down before the file was completely written. I also came across this article where a lot of people are facing this issue - https://social.msdn.microsoft.com/Forums/en-US/5c6096af-34e4-4dd5-bea0-ab130e498e3e/very-strange-phenomenon-output-file-filled-or-truncated-with-binary-zeros-what-could-cause-that. Some claim that it might be due to anti-virus. They've infact made it more fool proof by ensuring that the file is written to a temp location and copied to the actual location only if it is valid.

image

There is an if, else code in the PT Run view model.
@ryanbodrug-microsoft do we change it to try-catch to prevent such issues?

            if (_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
            {
                settings = _settingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
            }
            else
            {
                settings = new PowerLauncherSettings();
                settings.Properties.OpenPowerLauncher.Alt = true;
                settings.Properties.OpenPowerLauncher.Code = defaultKeyCode;
                settings.Properties.MaximumNumberOfResults = 4;
                callback(settings);
            }

I thought we battle hardened this a bit. Did we not do enough?

There were a lot of generic try-catch blocks in settings and they were masking issues and causing it to fail elsewhere so I think we removed generic try-catch blocks in some places. We wanted to find and fix the root cause of the issue rather than catching all exceptions. @ryanbodrug-microsoft can correct me here.

Though in this case, I think we should catch the exception and create a fresh settings file if it's corrupt.

I thought we did this on load.

I think it was my mistake. When we were facing crashes on settings and changed to settingsRepository to make loading generic, I replaced the try-catch general statements with if-else checks. Replacing the generic try-catches was necessary in a few places but I think I shouldn't have done that while loading. Shall make a PR to fix this.

Sometimes I get this pop-up and the settings.json is reset and this is done by the PowerLauncher process and it works as expected without the crash and the file is reset.
image

Looking at the code in PowerLauncher -

catch (JsonException e)
                {
                    if (retryCount > MaxRetries)
                    {
                        retry = false;
                        Log.Exception($"Failed to Deserialize PowerToys settings, Creating new settings as file could be corrupted {e.Message}", e, GetType());

                        // Settings.json could possibly be corrupted. To mitigate this we delete the
                        // current file and replace it with a correct json value.
                        _settingsUtils.DeleteSettings(PowerLauncherSettings.ModuleName);
                        CreateSettingsIfNotExists();
                        ErrorReporting.ShowMessageBox(Properties.Resources.deseralization_error_title, Properties.Resources.deseralization_error_message);
                    }
                    else
                    {
                        Thread.Sleep(1000);
                    }
                }

Looks like we should do something similar in settings as well. I shall try to repro it more later and think of an appropriate fix.

I deleted the settings.json file in C:\Users\AadiSahni\AppData\Local\Microsoft\PowerToys\PowerToys Run and it seems to work now

Reopening this issue to ensure that we have a fail safe when the settings.json file gets corrupted.

lets see if we can't get this in for 0.25

Hi @alekhyareddy28 @crutkas,
It seems the issue still persists. Please look into this.
Computer Information:
PowerToys version: v0.25.0
PowerToys Utility: PowerToys Run
Running PowerToys as Admin: Yes
Windows: Windows 10 Home 64 Bit, latest patch
Windows build number: Version 20H2 OS Build: 19042.630

Windows Specifications:
Edition Windows 10 Home
Version 20H2
OS build 19042.630
Experience Windows Feature Experience Pack 120.2212.31.0

Powertoys_crash
powertoys_crash1

Please find attached images for your reference.

Hi @mayankbaranwal1794, please create a new issue reporting this as the previous user reported that the issue no longer persists on deleting the settings.json file and we have also added a fail safe for it. It might be that the issue is different.

Also, when you create a new issue it would be great if you could specify the steps to reproduce it, what exactly you observe and share the settings files located at C:\Users\USERNAME\AppData\Local\Microsoft\PowerToys\ by replacing USERNAME with your system username.

Thank you.

Hi @alekhyareddy28, I've created a new issue yesterday. Please have a look.
https://github.com/microsoft/PowerToys/issues/8085

Was this page helpful?
0 / 5 - 0 ratings