Handle exceptions thrown by atom.workspace.scan()
This commit makes sure that async exceptions thrown are handled and
displayed correctly in the find and replace UI
MODIFY
lib/project-find-view.js
lib/project-find-view.js
@@ -318,7 +318,7 @@ class ProjectFindView {
return searchPromise;
}
- search(options) {
+ async search(options) {
// We always want to set the options passed in, even if we dont end up doing the search
if (options == null) { options = {}; }
this.model.getFindOptions().set(options);
@@ -330,13 +330,13 @@ class ProjectFindView {
let {onlyRunIfActive, onlyRunIfChanged} = options;
if ((onlyRunIfActive && !this.model.active) || !findPattern) return Promise.resolve();
- return this.showResultPane().then(() => {
+ await this.showResultPane()
+
try {
- return this.model.search(findPattern, pathsPattern, replacePattern, options);
+ return await this.model.search(findPattern, pathsPattern, replacePattern, options);
} catch (e) {
this.setErrorMessage(e.message);
}
- });
}
replaceAll() {

MODIFY
lib/project/results-model.js
lib/project/results-model.js
@@ -187,7 +187,7 @@ module.exports = class ResultsModel {
)
}
- search (findPattern, pathsPattern, replacePattern, options = {}) {
+ async search (findPattern, pathsPattern, replacePattern, options = {}) {
if (!this.shouldRerunSearch(findPattern, pathsPattern, options)) {
this.emitter.emit('did-noop-search')
return Promise.resolve()
@@ -236,7 +236,9 @@ module.exports = class ResultsModel {
})
this.emitter.emit('did-start-searching', this.inProgressSearchPromise)
- return this.inProgressSearchPromise.then(message => {
+
+ const message = await this.inProgressSearchPromise
+
if (message === 'cancelled') {
this.emitter.emit('did-cancel-searching')
} else {
@@ -246,7 +248,6 @@ module.exports = class ResultsModel {
this.inProgressSearchPromise = null
this.emitter.emit('did-finish-searching', resultsSummary)
}
- })
}
replace (pathsPattern, replacePattern, replacementPaths) {

Handle exceptions thrown by atom.workspace.scan()

This commit makes sure that async exceptions thrown are handled and
displayed correctly in the find and replace UI