-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(backup): improve backup export error handling and result encaps…
…ulation Introduced `BackupExportResult` and `ExportResult` to encapsulate and represent export operation outcomes, including success and specific failure types (`IOError`, `ZipError`). Refactored relevant methods to use these types, added coroutine support annotations, and implemented error handling for zipping and I/O operations. Added unit tests to ensure correct error handling behavior.
- Loading branch information
1 parent
a4e2968
commit effdec9
Showing
12 changed files
with
199 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
backup/src/commonMain/kotlin/com/wire/backup/dump/ExportResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.backup.dump | ||
|
||
internal sealed interface ExportResult { | ||
|
||
data object Success : ExportResult | ||
|
||
sealed class Failure(val message: String) : ExportResult { | ||
class IOError(message: String) : Failure(message) | ||
class ZipError(message: String) : Failure(message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
backup/src/commonTest/kotlin/com/wire/backup/dump/MPBackupExporterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.backup.dump | ||
|
||
import com.wire.backup.data.BackupQualifiedId | ||
import com.wire.backup.filesystem.BackupEntry | ||
import com.wire.backup.filesystem.EntryStorage | ||
import com.wire.backup.filesystem.InMemoryEntryStorage | ||
import kotlinx.coroutines.Deferred | ||
import kotlinx.coroutines.test.runTest | ||
import okio.Buffer | ||
import okio.Source | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertIs | ||
|
||
class MPBackupExporterTest { | ||
|
||
@Test | ||
fun givenZippingError_whenFinalizing_thenZipErrorShouldBeReturned() = runTest { | ||
val thrownException = IllegalStateException("Zipping failed!") | ||
val subject = object : CommonMPBackupExporter( | ||
BackupQualifiedId("user", "domain") | ||
) { | ||
override val storage: EntryStorage = InMemoryEntryStorage() | ||
|
||
override fun zipEntries(data: List<BackupEntry>): Deferred<Source> { | ||
throw thrownException | ||
} | ||
} | ||
|
||
val result = subject.finalize(null, Buffer()) | ||
assertIs<ExportResult.Failure.ZipError>(result) | ||
assertEquals(thrownException.message, result.message) | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
backup/src/jsMain/kotlin/com/wire/backup/dump/BackupExportResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.backup.dump | ||
|
||
@JsExport | ||
public sealed class BackupExportResult { | ||
public class Success(public val bytes: ByteArray) : BackupExportResult() | ||
public sealed class Failure(public val message: String) : BackupExportResult() { | ||
/** | ||
* Represents an I/O error that occurs during an export process. | ||
* | ||
* It's unlikely for this to ever be thrown on JavaScript/Browser | ||
*/ | ||
public class IOError(message: String) : Failure(message) | ||
|
||
/** | ||
* An error happened during the zipping process. | ||
*/ | ||
public class ZipError(message: String) : Failure(message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
backup/src/nonJsMain/kotlin/com/wire/backup/dump/BackupExportResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2025 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.backup.dump | ||
|
||
public sealed interface BackupExportResult { | ||
/** | ||
* Represents a successful result of a backup export operation. | ||
* | ||
* @property pathToOutputFile The path to the resulting output file of the export. | ||
*/ | ||
public class Success(public val pathToOutputFile: String) : BackupExportResult | ||
public sealed interface Failure : BackupExportResult { | ||
public val message: String | ||
|
||
/** | ||
* Represents an I/O error that occurs during an export process. | ||
*/ | ||
public class IOError(override val message: String) : Failure | ||
|
||
/** | ||
* An error happened during the zipping process. | ||
*/ | ||
public class ZipError(override val message: String) : Failure | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters