{"record":{"id":"0cb55a232bb27045","repo":"MuntashirAkon/AppManager","slug":"failed-to-write-metadata-sbconverter","errorCode":null,"errorMessage":"Failed to write metadata.","messagePattern":"Failed to write metadata\\.","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/convert/SBConverter.java","lineNumber":134,"sourceCode":"            } catch (IOException e) {\n                throw new BackupException(\"Failed to create checksum file.\", e);\n            }\n            // Backup icon\n            backupIcon();\n            if (mDestMetadata.info.flags.backupApkFiles()) {\n                backupApkFile();\n            }\n            if (mDestMetadata.info.flags.backupData()) {\n                backupData();\n            }\n            // Write modified metadata\n            try {\n                Map<String, String> filenameChecksumMap = MetadataManager.writeMetadata(mDestMetadata, mBackupItem);\n                for (Map.Entry<String, String> filenameChecksumPair : filenameChecksumMap.entrySet()) {\n                    mChecksum.add(filenameChecksumPair.getKey(), filenameChecksumPair.getValue());\n                }\n            } catch (IOException e) {\n                throw new BackupException(\"Failed to write metadata.\");\n            }\n            mChecksum.close();\n            // Encrypt checksum\n            try {\n                mBackupItem.encrypt(new Path[]{mChecksum.getFile()});\n            } catch (IOException e) {\n                throw new BackupException(\"Failed to encrypt checksums.txt\");\n            }\n            // Replace current backup\n            try {\n                mBackupItem.commit();\n            } catch (IOException e) {\n                throw new BackupException(\"Could not finalise backup.\", e);\n            }\n            backupSuccess = true;\n        } catch (BackupException e) {\n            throw e;\n        } catch (Throwable th) {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/convert/SBConverter.java#L116-L152","documentation":"SBConverter.convert throws BackupException('Failed to write metadata.') when MetadataManager.writeMetadata throws IOException while serializing destination metadata files into the backup. Note this rethrow drops the cause (no 'e' argument), hiding the root IOException.","triggerScenarios":"writeMetadata fails writing the metadata JSON files to the backup directory — unwritable directory, full storage, or I/O error during file creation.","commonSituations":"Destination storage full or read-only; stale backup directories with leftover files; filesystem errors on emulated storage.","solutions":["Check free space and writability of the backup destination","Inspect the original IOException in logcat since the BackupException omits the cause","Remove stale backup directories for the same package/name and retry","Verify storage permissions before conversion"],"exampleFix":"// before\n} catch (IOException e) {\n    throw new BackupException(\"Failed to write metadata.\");\n}\n// after\n} catch (IOException e) {\n    throw new BackupException(\"Failed to write metadata.\", e);\n}","handlingStrategy":"try-catch","validationCode":"if (mDestMetadata == null || mDestMetadata.info == null) {\n    throw new IllegalStateException(\"Destination metadata not initialized before write\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    converter.convert(...);\n} catch (BackupException e) {\n    if (\"Failed to write metadata.\".equals(e.getMessage())) {\n        // check logcat for the suppressed IOException cause; fix storage and retry\n    }\n}","preventionTips":["Ensure metadata is fully populated before writing","Check destination writability/free space","Initialize mChecksum and backup item before metadata write"],"tags":["android","backup","metadata","io"],"backgroundTag":"file-write-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}