@@ -13,7 +13,7 @@ import com.androidvip.sysctlgui.domain.exceptions.InvalidFileExtensionException
1313import com.androidvip.sysctlgui.domain.exceptions.MalformedLineException
1414import com.androidvip.sysctlgui.domain.exceptions.NoParameterFoundException
1515import com.androidvip.sysctlgui.domain.exceptions.NoValidParamException
16- import com.androidvip.sysctlgui.domain.models .ViewState
16+ import com.androidvip.sysctlgui.utils .ViewState
1717import com.androidvip.sysctlgui.domain.usecase.BackupParamsUseCase
1818import com.androidvip.sysctlgui.domain.usecase.ExportParamsUseCase
1919import com.androidvip.sysctlgui.domain.usecase.ImportParamsUseCase
@@ -79,7 +79,7 @@ class ExportOptionsViewModel(
7979 val postError: (Int ) -> Unit = {
8080 _viewEffect .postValue(ExportOptionsViewEffect .ShowImportError (it))
8181 }
82- val result = importParamsUseCase.execute (stream, fileExtension)
82+ val result = runCatching { importParamsUseCase(stream, fileExtension) }
8383 when (result.exceptionOrNull()) {
8484 is JsonParseException ,
8585 is JsonSyntaxException -> postError(R .string.import_error_invalid_json)
@@ -137,20 +137,24 @@ class ExportOptionsViewModel(
137137 target : Uri ,
138138 context : Context
139139 ): Result <Unit > = withContext(ioDispatcher) {
140- val descriptor = context.contentResolver.openFileDescriptor(target, " w" )
141- ? : return @withContext Result .failure(IOException ())
140+ return @withContext runCatching {
141+ val descriptor = context.contentResolver.openFileDescriptor(target, " w" )
142+ ? : throw IOException ()
142143
143- return @withContext exportParamsUseCase.execute(descriptor.fileDescriptor)
144+ exportParamsUseCase(descriptor.fileDescriptor)
145+ }
144146 }
145147
146148 private suspend fun backUpParamsWithFileDescriptor (
147149 target : Uri ,
148150 context : Context
149151 ): Result <Unit > = withContext(ioDispatcher) {
150- val descriptor = context.contentResolver.openFileDescriptor(target, " w" )
151- ? : return @withContext Result .failure(IOException ())
152+ return @withContext runCatching {
153+ val descriptor = context.contentResolver.openFileDescriptor(target, " w" )
154+ ? : throw IOException ()
152155
153- return @withContext backupParamsUseCase.execute(descriptor.fileDescriptor)
156+ backupParamsUseCase(descriptor.fileDescriptor)
157+ }
154158 }
155159
156160 private val currentViewState: ViewState <Unit >
0 commit comments