mirror of
https://github.com/laurent22/joplin.git
synced 2025-02-04 19:16:07 +02:00
All: Improve error message when revision metadata cannot be decoded, to improve debugging
This commit is contained in:
parent
ff79745d28
commit
a325bf6dc6
@ -78,7 +78,7 @@ export default class Revision extends BaseItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
static createObjectPatch(oldObject: any, newObject: any) {
|
||||
public static createObjectPatch(oldObject: any, newObject: any) {
|
||||
if (!oldObject) oldObject = {};
|
||||
|
||||
const output: any = {
|
||||
@ -237,7 +237,7 @@ export default class Revision extends BaseItem {
|
||||
}
|
||||
|
||||
// Note: revs must be sorted by update_time ASC (as returned by allByType)
|
||||
static async mergeDiffs(revision: RevisionEntity, revs: RevisionEntity[] = null) {
|
||||
public static async mergeDiffs(revision: RevisionEntity, revs: RevisionEntity[] = null) {
|
||||
if (!('encryption_applied' in revision) || !!revision.encryption_applied) throw new JoplinError('Target revision is encrypted', 'revision_encrypted');
|
||||
|
||||
if (!revs) {
|
||||
@ -273,7 +273,12 @@ export default class Revision extends BaseItem {
|
||||
if (rev.encryption_applied) throw new JoplinError(sprintf('Revision "%s" is encrypted', rev.id), 'revision_encrypted');
|
||||
output.title = this.applyTextPatch(output.title, rev.title_diff);
|
||||
output.body = this.applyTextPatch(output.body, rev.body_diff);
|
||||
output.metadata = this.applyObjectPatch(output.metadata, rev.metadata_diff);
|
||||
try {
|
||||
output.metadata = this.applyObjectPatch(output.metadata, rev.metadata_diff);
|
||||
} catch (error) {
|
||||
error.message = `Revision ${rev.id}: Could not apply patch: ${error.message}: ${rev.metadata_diff}`;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
@ -472,4 +472,35 @@ describe('services_Revision', function() {
|
||||
expect(Date.now() - interval < timeRev2).toBe(true); // check the computer is not too slow for this test
|
||||
expect((await Revision.all()).length).toBe(2);
|
||||
}));
|
||||
|
||||
it('should give a detailed error when a patch cannot be applied', async () => {
|
||||
const n1_v0 = await Note.save({ title: '', is_todo: 1, todo_completed: 0 });
|
||||
const n1_v1 = await Note.save({ id: n1_v0.id, title: 'hello' });
|
||||
await revisionService().collectRevisions(); // REV 1
|
||||
await time.msleep(100);
|
||||
|
||||
await Note.save({ id: n1_v1.id, title: 'hello welcome', todo_completed: 1000 });
|
||||
await revisionService().collectRevisions(); // REV 2
|
||||
|
||||
// Corrupt the metadata diff to generate the error - we assume that it's
|
||||
// been truncated for whatever reason.
|
||||
|
||||
const corruptedMetadata = '{"new":{"todo_completed":10';
|
||||
const revId2 = (await Revision.all())[1].id;
|
||||
await Revision.save({ id: revId2, metadata_diff: corruptedMetadata });
|
||||
|
||||
const note = await Note.load(n1_v0.id);
|
||||
let error = null;
|
||||
try {
|
||||
await revisionService().createNoteRevision_(note);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain(revId2);
|
||||
expect(error.message).toContain(note.id);
|
||||
expect(error.message).toContain(corruptedMetadata);
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user