Avoid unneeded std::string casts in exception handling

This commit is contained in:
Ilya Fedin 2023-09-19 17:10:53 +04:00 committed by John Preston
parent a54bc449e4
commit e0b4d1edce
4 changed files with 10 additions and 17 deletions

View File

@ -26,8 +26,7 @@ void UnsafeOpenUrl(const QString &url) {
base::Platform::AppLaunchContext()); base::Platform::AppLaunchContext());
if (!result) { if (!result) {
LOG(("App Error: %1").arg( LOG(("App Error: %1").arg(result.error().what()));
QString::fromStdString(result.error().what())));
} else if (*result) { } else if (*result) {
return; return;
} }
@ -52,8 +51,7 @@ void UnsafeLaunch(const QString &filepath) {
if ([&] { if ([&] {
const auto filename = GLib::filename_to_uri(filepath.toStdString()); const auto filename = GLib::filename_to_uri(filepath.toStdString());
if (!filename) { if (!filename) {
LOG(("App Error: %1").arg( LOG(("App Error: %1").arg(filename.error().what()));
QString::fromStdString(filename.error().what())));
return false; return false;
} }
@ -63,8 +61,7 @@ void UnsafeLaunch(const QString &filepath) {
base::Platform::AppLaunchContext()); base::Platform::AppLaunchContext());
if (!result) { if (!result) {
LOG(("App Error: %1").arg( LOG(("App Error: %1").arg(result.error().what()));
QString::fromStdString(result.error().what())));
return false; return false;
} }

View File

@ -174,7 +174,7 @@ gi::ref_ptr<Application> MakeApplication() {
const auto result = gi::make_ref<Application>(); const auto result = gi::make_ref<Application>();
if (const auto registered = result->register_(); !registered) { if (const auto registered = result->register_(); !registered) {
LOG(("App Error: Failed to register: %1").arg( LOG(("App Error: Failed to register: %1").arg(
QString::fromStdString(registered.error().message_()))); registered.error().message_().c_str()));
return nullptr; return nullptr;
} }
return result; return result;

View File

@ -58,8 +58,7 @@ void Noexcept(Fn<void()> callback, Fn<void()> failed = nullptr) noexcept {
callback(); callback();
return; return;
} catch (const std::exception &e) { } catch (const std::exception &e) {
LOG(("Native Notification Error: %1").arg( LOG(("Native Notification Error: %1").arg(e.what()));
QString::fromStdString(e.what())));
} }
if (failed) { if (failed) {

View File

@ -68,8 +68,7 @@ void PortalAutostart(bool enabled, Fn<void(bool)> done) {
Gio::DBus::BusType::SESSION); Gio::DBus::BusType::SESSION);
} catch (const std::exception &e) { } catch (const std::exception &e) {
if (done) { if (done) {
LOG(("Portal Autostart Error: %1").arg( LOG(("Portal Autostart Error: %1").arg(e.what()));
QString::fromStdString(e.what())));
} }
return Glib::RefPtr<Gio::DBus::Connection>(); return Glib::RefPtr<Gio::DBus::Connection>();
} }
@ -144,8 +143,7 @@ void PortalAutostart(bool enabled, Fn<void(bool)> done) {
} }
} catch (const std::exception &e) { } catch (const std::exception &e) {
if (done) { if (done) {
LOG(("Portal Autostart Error: %1").arg( LOG(("Portal Autostart Error: %1").arg(e.what()));
QString::fromStdString(e.what())));
done(false); done(false);
} }
} }
@ -174,8 +172,7 @@ void PortalAutostart(bool enabled, Fn<void(bool)> done) {
connection->call_finish(result); connection->call_finish(result);
} catch (const std::exception &e) { } catch (const std::exception &e) {
if (done) { if (done) {
LOG(("Portal Autostart Error: %1").arg( LOG(("Portal Autostart Error: %1").arg(e.what()));
QString::fromStdString(e.what())));
done(false); done(false);
} }
@ -286,7 +283,7 @@ bool GenerateDesktopFile(
target->save_to_file(targetFile.toStdString()); target->save_to_file(targetFile.toStdString());
} catch (const std::exception &e) { } catch (const std::exception &e) {
if (!silent) { if (!silent) {
LOG(("App Error: %1").arg(QString::fromStdString(e.what()))); LOG(("App Error: %1").arg(e.what()));
} }
return false; return false;
} }
@ -378,7 +375,7 @@ bool GenerateServiceFile(bool silent = false) {
target->save_to_file(targetFile.toStdString()); target->save_to_file(targetFile.toStdString());
} catch (const std::exception &e) { } catch (const std::exception &e) {
if (!silent) { if (!silent) {
LOG(("App Error: %1").arg(QString::fromStdString(e.what()))); LOG(("App Error: %1").arg(e.what()));
} }
return false; return false;
} }