text files - move revert() error handler into model

This commit is contained in:
Benjamin Pasero
2020-01-26 09:30:33 +01:00
parent 432961cb0d
commit f5a52f87cf
2 changed files with 13 additions and 22 deletions
@@ -598,26 +598,13 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
});
await Promise.all(fileModels.map(async model => {
try {
await model.revert(options);
await model.revert(options);
// If model is still dirty, mark the resulting operation as error
if (model.isDirty()) {
const result = mapResourceToResult.get(model.resource);
if (result) {
result.error = true;
}
}
} catch (error) {
// FileNotFound means the file got deleted meanwhile, so ignore it
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND) {
return;
}
// Otherwise bubble up the error
else {
throw error;
// If model is still dirty, mark the resulting operation as error
if (model.isDirty()) {
const result = mapResourceToResult.get(model.resource);
if (result) {
result.error = true;
}
}
}));
@@ -230,10 +230,14 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
await this.load({ forceReadFromDisk: true });
} catch (error) {
// Set flags back to previous values, we are still dirty if revert failed
undo();
// FileNotFound means the file got deleted meanwhile, so ignore it
if ((<FileOperationError>error).fileOperationResult !== FileOperationResult.FILE_NOT_FOUND) {
throw error;
// Set flags back to previous values, we are still dirty if revert failed
undo();
throw error;
}
}
}