Skip to content

Commit d9f49fa

Browse files
committed
microsoft#98389 fix tests
1 parent 7962634 commit d9f49fa

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/vs/platform/userDataSync/common/abstractSynchronizer.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ export interface ISyncData {
4141

4242
function isSyncData(thing: any): thing is ISyncData {
4343
if (thing
44-
&& (thing.version && typeof thing.version === 'number')
45-
&& (thing.content && typeof thing.content === 'string')) {
44+
&& (thing.version !== undefined && typeof thing.version === 'number')
45+
&& (thing.content !== undefined && typeof thing.content === 'string')) {
4646

4747
// backward compatibility
4848
if (Object.keys(thing).length === 2) {
4949
return true;
5050
}
5151

5252
if (Object.keys(thing).length === 3
53-
&& (thing.machineId && typeof thing.machineId === 'string')) {
53+
&& (thing.machineId !== undefined && typeof thing.machineId === 'string')) {
5454
return true;
5555
}
5656
}
@@ -356,9 +356,13 @@ export abstract class AbstractSynchroniser extends Disposable {
356356
}
357357

358358
protected parseSyncData(content: string): ISyncData {
359-
const syncData: ISyncData = JSON.parse(content);
360-
if (isSyncData(syncData)) {
361-
return syncData;
359+
try {
360+
const syncData: ISyncData = JSON.parse(content);
361+
if (isSyncData(syncData)) {
362+
return syncData;
363+
}
364+
} catch (error) {
365+
this.logService.error(error);
362366
}
363367
throw new UserDataSyncError(localize('incompatible sync data', "Cannot parse sync data as it is not compatible with current version."), UserDataSyncErrorCode.Incompatible, this.resource);
364368
}

src/vs/platform/userDataSync/test/common/synchronizer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class TestSynchroniser extends AbstractSynchroniser {
4242
protected async performReplace(syncData: ISyncData, remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null): Promise<void> { }
4343

4444
async apply(ref: string): Promise<void> {
45-
ref = await this.userDataSyncStoreService.write(this.resource, '', ref);
46-
await this.updateLastSyncUserData({ ref, syncData: { content: '', version: this.version } });
45+
const remoteUserData = await this.updateRemoteUserData('', ref);
46+
await this.updateLastSyncUserData(remoteUserData);
4747
}
4848

4949
async stop(): Promise<void> {

0 commit comments

Comments
 (0)