Skip to content

Commit f39359b

Browse files
CopilotMuyuanMS
andauthored
Fix LightSwitch crash: catch all exceptions in update_sun_times and guard add_property against missing properties key
Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/8940919c-1eef-4a10-9abc-a0defbc156d8 Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
1 parent 9ba06a5 commit f39359b

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/common/SettingsAPI/settings_objects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ namespace PowerToysSettings
7878
{
7979
json::JsonObject prop_value;
8080
prop_value.SetNamedValue(L"value", json::value(value));
81+
if (!m_json.HasKey(L"properties"))
82+
{
83+
m_json.SetNamedValue(L"properties", json::JsonObject{});
84+
}
8185
m_json.GetNamedObject(L"properties").SetNamedValue(name, prop_value);
8286
}
8387

src/modules/LightSwitch/LightSwitchService/LightSwitchStateManager.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,9 @@ static std::pair<int, int> update_sun_times(auto& settings)
143143

144144
Logger::info(L"[LightSwitchService] Updated sun times and saved to config.");
145145
}
146-
catch (const std::exception& e)
146+
catch (...)
147147
{
148-
std::string msg = e.what();
149-
std::wstring wmsg(msg.begin(), msg.end());
150-
Logger::error(L"[LightSwitchService] Exception during sun time update: {}", wmsg);
148+
Logger::error(L"[LightSwitchService] Exception during sun time update.");
151149
}
152150

153151
return { newLightTime, newDarkTime };

0 commit comments

Comments
 (0)