feat: Improve error handling in configuration modification function

- Added detailed error messages for configuration file modification failures
- Enhanced logging to provide specific guidance for manual configuration updates
- Maintained existing key replacement and addition logic
- Improved user feedback for configuration modification errors
This commit is contained in:
煎饼果子卷鲨鱼辣椒 2025-02-07 10:23:56 +08:00
parent 1ac23403e5
commit 89751a79c3

View File

@ -178,12 +178,14 @@ modify_or_add_config() {
# key存在,执行替换
if ! sed -i '' -e "s/\"$key\":[[:space:]]*\"[^\"]*\"/\"$key\": \"$value\"/" "$file"; then
log_error "修改配置失败: $key"
log_error "请手动修改配置文件: $file"
return 1
fi
else
# key不存在,添加新的key-value对
if ! sed -i '' -e "s/}$/,\n \"$key\": \"$value\"\n}/" "$file"; then
log_error "添加配置失败: $key"
log_error "请手动修改配置文件: $file"
return 1
fi
fi