fix: validate filename before using it to avoid crash (#10138)

When custom mode is enabled and filename is not set, the program will crash.
This patch adds a check to validate the filename before using it to avoid the crash.
This commit is contained in:
Loong
2024-08-09 16:50:17 +01:00
committed by GitHub
parent b3e1cba56b
commit 3994e845ad

View File

@@ -143,7 +143,12 @@ bool asst::InfrastTask::set_params(const json::value& params)
m_replenish_task_ptr->set_enable(replenish);
if (is_custom && !m_running) {
std::string filename = params.at("filename").as_string();
auto filename_opt = params.find<std::string>("filename");
if (!filename_opt) {
Log.error("filename is not set while custom mode is enabled");
return false;
}
std::string filename = filename_opt.value();
int index = params.get("plan_index", 0);
try {