Skip to content

Commit 441e609

Browse files
committed
microsoft#90218 create user data sync error for invalid local content
1 parent 74f639e commit 441e609

8 files changed

Lines changed: 20 additions & 20 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export abstract class AbstractFileSynchroniser extends AbstractSynchroniser {
217217
} catch (e) {
218218
if ((e instanceof FileSystemProviderError && e.code === FileSystemProviderErrorCode.FileExists) ||
219219
(e instanceof FileOperationError && e.fileOperationResult === FileOperationResult.FILE_MODIFIED_SINCE)) {
220-
throw new UserDataSyncError(e.message, UserDataSyncErrorCode.NewLocal);
220+
throw new UserDataSyncError(e.message, UserDataSyncErrorCode.LocalPreconditionFailed);
221221
} else {
222222
throw e;
223223
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class ExtensionsSynchroniser extends AbstractSynchroniser implements IUse
151151
await this.apply(previewResult);
152152
} catch (e) {
153153
this.setStatus(SyncStatus.Idle);
154-
if (e instanceof UserDataSyncError && e.code === UserDataSyncErrorCode.Rejected) {
154+
if (e instanceof UserDataSyncError && e.code === UserDataSyncErrorCode.RemotePreconditionFailed) {
155155
// Rejected as there is a new remote version. Syncing again,
156156
this.logService.info('Extensions: Failed to synchronize extensions as there is a new remote version available. Synchronizing again...');
157157
return this.sync();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class GlobalStateSynchroniser extends AbstractSynchroniser implements IUs
126126
this.logService.trace('UI State: Finished synchronizing ui state.');
127127
} catch (e) {
128128
this.setStatus(SyncStatus.Idle);
129-
if (e instanceof UserDataSyncError && e.code === UserDataSyncErrorCode.Rejected) {
129+
if (e instanceof UserDataSyncError && e.code === UserDataSyncErrorCode.RemotePreconditionFailed) {
130130
// Rejected as there is a new remote version. Syncing again,
131131
this.logService.info('UI State: Failed to synchronize ui state as there is a new remote version available. Synchronizing again...');
132132
return this.sync();

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ export class KeybindingsSynchroniser extends AbstractJsonFileSynchroniser implem
179179
this.setStatus(SyncStatus.Idle);
180180
if (e instanceof UserDataSyncError) {
181181
switch (e.code) {
182-
case UserDataSyncErrorCode.Rejected:
182+
case UserDataSyncErrorCode.RemotePreconditionFailed:
183183
// Rejected as there is a new remote version. Syncing again,
184184
this.logService.info('Keybindings: Failed to synchronize keybindings as there is a new remote version available. Synchronizing again...');
185185
return this.sync();
186-
case UserDataSyncErrorCode.NewLocal:
186+
case UserDataSyncErrorCode.LocalPreconditionFailed:
187187
// Rejected as there is a new local version. Syncing again.
188188
this.logService.info('Keybindings: Failed to synchronize keybindings as there is a new local version available. Synchronizing again...');
189189
return this.sync(remoteUserData.ref);
@@ -202,9 +202,7 @@ export class KeybindingsSynchroniser extends AbstractJsonFileSynchroniser implem
202202

203203
if (content !== null) {
204204
if (this.hasErrors(content)) {
205-
const error = new Error(localize('errorInvalidKeybindings', "Unable to sync keybindings. Please resolve conflicts without any errors/warnings and try again."));
206-
this.logService.error(error);
207-
throw error;
205+
throw new UserDataSyncError(localize('errorInvalidSettings', "Unable to sync keybindings as there are errors/warning in keybindings file."), UserDataSyncErrorCode.LocalInvalidContent, this.source);
208206
}
209207

210208
if (hasLocalChanged) {
@@ -261,8 +259,7 @@ export class KeybindingsSynchroniser extends AbstractJsonFileSynchroniser implem
261259
if (remoteContent) {
262260
const localContent: string = fileContent ? fileContent.value.toString() : '[]';
263261
if (this.hasErrors(localContent)) {
264-
this.logService.error('Keybindings: Unable to sync keybindings as there are errors/warning in keybindings file.');
265-
return { fileContent, remoteUserData, lastSyncUserData, content, hasLocalChanged, hasRemoteChanged, hasConflicts };
262+
throw new UserDataSyncError(localize('errorInvalidSettings', "Unable to sync keybindings as there are errors/warning in keybindings file."), UserDataSyncErrorCode.LocalInvalidContent, this.source);
266263
}
267264

268265
if (!lastSyncContent // First time sync

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
221221
this.setStatus(SyncStatus.Idle);
222222
if (e instanceof UserDataSyncError) {
223223
switch (e.code) {
224-
case UserDataSyncErrorCode.Rejected:
224+
case UserDataSyncErrorCode.RemotePreconditionFailed:
225225
// Rejected as there is a new remote version. Syncing again,
226226
this.logService.info('Settings: Failed to synchronize settings as there is a new remote version available. Synchronizing again...');
227227
return this.sync();
228-
case UserDataSyncErrorCode.NewLocal:
228+
case UserDataSyncErrorCode.LocalPreconditionFailed:
229229
// Rejected as there is a new local version. Syncing again.
230230
this.logService.info('Settings: Failed to synchronize settings as there is a new local version available. Synchronizing again...');
231231
return this.sync(remoteUserData.ref);
@@ -245,9 +245,7 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
245245
if (content !== null) {
246246

247247
if (this.hasErrors(content)) {
248-
const error = new Error(localize('errorInvalidSettings', "Unable to sync settings. Please resolve conflicts without any errors/warnings and try again."));
249-
this.logService.error(error);
250-
throw error;
248+
throw new UserDataSyncError(localize('errorInvalidSettings', "Unable to sync settings as there are errors/warning in settings file."), UserDataSyncErrorCode.LocalInvalidContent, this.source);
251249
}
252250

253251
if (hasLocalChanged) {
@@ -304,7 +302,7 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
304302

305303
// No action when there are errors
306304
if (this.hasErrors(localContent)) {
307-
this.logService.error('Settings: Unable to sync settings as there are errors/warning in settings file.');
305+
throw new UserDataSyncError(localize('errorInvalidSettings', "Unable to sync settings as there are errors/warning in settings file."), UserDataSyncErrorCode.LocalInvalidContent, this.source);
308306
}
309307

310308
else {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,19 @@ export interface IUserDataSyncStoreService {
154154
// #region User Data Sync Error
155155

156156
export enum UserDataSyncErrorCode {
157+
// Server Errors
157158
Unauthorized = 'Unauthorized',
158159
Forbidden = 'Forbidden',
159160
ConnectionRefused = 'ConnectionRefused',
160-
Rejected = 'Rejected',
161+
RemotePreconditionFailed = 'RemotePreconditionFailed',
161162
TooLarge = 'TooLarge',
162163
NoRef = 'NoRef',
163-
NewLocal = 'NewLocal',
164164
TurnedOff = 'TurnedOff',
165+
166+
// Local Errors
167+
LocalPreconditionFailed = 'LocalPreconditionFailed',
168+
LocalInvalidContent = 'LocalInvalidContent',
169+
165170
Unknown = 'Unknown',
166171
}
167172

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class UserDataSyncStoreService extends Disposable implements IUserDataSyn
142142
}
143143

144144
if (context.res.statusCode === 412) {
145-
throw new UserDataSyncStoreError(`${options.type} request '${options.url?.toString()}' failed because of Precondition Failed (412). There is new data exists for this resource. Make the request again with latest data.`, UserDataSyncErrorCode.Rejected, source);
145+
throw new UserDataSyncStoreError(`${options.type} request '${options.url?.toString()}' failed because of Precondition Failed (412). There is new data exists for this resource. Make the request again with latest data.`, UserDataSyncErrorCode.RemotePreconditionFailed, source);
146146
}
147147

148148
if (context.res.statusCode === 413) {

src/vs/workbench/contrib/userDataSync/browser/userDataSync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ class AcceptChangesContribution extends Disposable implements IEditorContributio
832832
try {
833833
await this.userDataSyncService.accept(conflictsSource, model.getValue());
834834
} catch (e) {
835-
if (e instanceof UserDataSyncError && e.code === UserDataSyncErrorCode.NewLocal) {
835+
if (e instanceof UserDataSyncError && e.code === UserDataSyncErrorCode.LocalPreconditionFailed) {
836836
if (this.userDataSyncService.conflictsSources.indexOf(conflictsSource) !== -1) {
837837
this.notificationService.warn(localize('update conflicts', "Could not resolve conflicts as there is new local version available. Please try again."));
838838
}

0 commit comments

Comments
 (0)