Skip to content

Commit

Permalink
Fix make_format_args() calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashaduri committed May 14, 2024
1 parent 84ae416 commit 6d49968
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
15 changes: 10 additions & 5 deletions src/applib/selftest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ hz::ExpectedVoid<SelfTestExecutionError> SelfTest::start(const std::shared_ptr<C
}
if (!this->is_supported()) {
// Translators: {} is a test name - Short test, etc.
std::string type_name = get_test_displayable_name(type_);
return hz::Unexpected(SelfTestExecutionError::UnsupportedTest,
std::vformat(_("{} is unsupported by this drive."), std::make_format_args(get_test_displayable_name(type_))));
std::vformat(_("{} is unsupported by this drive."), std::make_format_args(type_name)));
}

std::string test_param;
Expand All @@ -230,8 +231,9 @@ hz::ExpectedVoid<SelfTestExecutionError> SelfTest::start(const std::shared_ptr<C
auto execute_status = drive_->execute_device_smartctl("--test=" + test_param, smartctl_ex, output);

if (!execute_status.has_value()) {
std::string message = execute_status.error().message();
return hz::Unexpected(SelfTestExecutionError::CommandFailed,
std::vformat(_("Sending command to drive failed: {}"), std::make_format_args(execute_status.error().message())));
std::vformat(_("Sending command to drive failed: {}"), std::make_format_args(message)));
}

bool ata_test_started = app_pcre_match(R"(/^Drive command .* successful\.\nTesting has begun\.$/mi)", output);
Expand Down Expand Up @@ -297,8 +299,9 @@ hz::ExpectedVoid<SelfTestExecutionError> SelfTest::force_stop(const std::shared_
auto execute_status = drive_->execute_device_smartctl("--abort", smartctl_ex, output);

if (!execute_status) {
std::string message = execute_status.error().message();
return hz::Unexpected(SelfTestExecutionError::CommandFailed,
std::vformat(_("Sending command to drive failed: {}"), std::make_format_args(execute_status.error().message())));
std::vformat(_("Sending command to drive failed: {}"), std::make_format_args(message)));
}

// this command prints success even if no test was running.
Expand All @@ -324,8 +327,9 @@ hz::ExpectedVoid<SelfTestExecutionError> SelfTest::force_stop(const std::shared_
}

if (!update_status) { // update can error out too.
std::string message = update_status.error().message();
return hz::Unexpected(SelfTestExecutionError::UpdateError,
std::vformat(_("Error fetching test progress information: {}"), std::make_format_args(update_status.error().message())));
std::vformat(_("Error fetching test progress information: {}"), std::make_format_args(message)));
}

return {}; // everything ok
Expand Down Expand Up @@ -360,8 +364,9 @@ hz::ExpectedVoid<SelfTestExecutionError> SelfTest::update(const std::shared_ptr<
auto execute_status = drive_->execute_device_smartctl(command_options, smartctl_ex, output);

if (!execute_status) {
std::string message = execute_status.error().message();
return hz::Unexpected(SelfTestExecutionError::CommandFailed,
std::vformat(_("Sending command to drive failed: {}"), std::make_format_args(execute_status.error().message())));
std::vformat(_("Sending command to drive failed: {}"), std::make_format_args(message)));
}


Expand Down
3 changes: 2 additions & 1 deletion src/applib/smartctl_json_parser_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ auto integer_formatter(const std::string& format_string = "{}")
StorageProperty p;
p.set_name(key, key, displayable_name);
// p.reported_value = (jval.value() ? true_str : false_str);
p.readable_value = std::vformat(format_string, std::make_format_args(hz::number_to_string_locale(jval.value())));
std::string num_str = hz::number_to_string_locale(jval.value());
p.readable_value = std::vformat(format_string, std::make_format_args(num_str));
p.value = jval.value();
return p;
}
Expand Down
3 changes: 2 additions & 1 deletion src/applib/storage_detector_other.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ hz::ExpectedVoid<StorageDetectorError> detect_drives_other(std::vector<StorageDe
}
if (ec) {
debug_out_error("app", DBG_FUNC_MSG << "Cannot list device directory entries.\n");
std::string message = ec.message();
return hz::Unexpected(StorageDetectorError::DevOpenError,
std::vformat(_("Cannot list device directory entries: {}"), std::make_format_args(ec.message())));
std::vformat(_("Cannot list device directory entries: {}"), std::make_format_args(message)));
}


Expand Down
12 changes: 8 additions & 4 deletions src/applib/storage_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ hz::ExpectedVoid<StorageDeviceError> StorageDevice::parse_basic_data()
// This also fills the drive type properties.
auto parse_status = basic_parser->parse(this->get_basic_output());
if (!parse_status) {
std::string message = parse_status.error().message();
return hz::Unexpected(StorageDeviceError::ParseError,
std::vformat(_("Cannot parse smartctl output: {}"), std::make_format_args(parse_status.error().message())));
std::vformat(_("Cannot parse smartctl output: {}"), std::make_format_args(message)));
}

// See if we can narrow down the drive type from what was detected
Expand Down Expand Up @@ -357,8 +358,9 @@ hz::ExpectedVoid<StorageDeviceError> StorageDevice::try_parse_data()
auto basic_parse_status = this->parse_basic_data(true); // will add some properties too. this will emit signal_changed().
if (!basic_parse_status) {
// return full parser's error messages - they are more detailed.
std::string message = basic_parse_status.error().message();
return hz::Unexpected(StorageDeviceError::ParseError,
std::vformat(_("Cannot parse smartctl output: {}"), std::make_format_args(parse_status.error().message())));
std::vformat(_("Cannot parse smartctl output: {}"), std::make_format_args(message)));
}
return {}; // return ok if at least the info was ok.
Expand Down Expand Up @@ -393,8 +395,9 @@ hz::ExpectedVoid<StorageDeviceError> StorageDevice::parse_full_data(SmartctlPars
return {};
}

std::string message = parse_status.error().message();
return hz::Unexpected(StorageDeviceError::ParseError,
std::vformat(_("Cannot parse smartctl output: {}"), std::make_format_args(parse_status.error().message())));
std::vformat(_("Cannot parse smartctl output: {}"), std::make_format_args(message)));
}


Expand All @@ -417,8 +420,9 @@ hz::ExpectedVoid<StorageDeviceError> StorageDevice::parse_any_data_for_virtual()
// This will add some properties and emit signal_changed().
auto basic_parse_status = basic_parser->parse(this->full_output_);
if (!basic_parse_status) {
std::string message = basic_parse_status.error().message();
return hz::Unexpected(StorageDeviceError::ParseError,
std::vformat(_("Cannot parse smartctl output: {}"), std::make_format_args(basic_parse_status.error().message())));
std::vformat(_("Cannot parse smartctl output: {}"), std::make_format_args(message)));
}

auto basic_property_repo = basic_parser->get_property_repository();
Expand Down

0 comments on commit 6d49968

Please sign in to comment.