Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Handle exceptions thrown by atom.workspace.scan()
Browse files Browse the repository at this point in the history
This commit makes sure that async exceptions thrown are handled and
displayed correctly in the find and replace UI
  • Loading branch information
rafeca committed May 22, 2019
1 parent 04568a1 commit e2600aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
16 changes: 8 additions & 8 deletions lib/project-find-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -330,13 +330,13 @@ class ProjectFindView {
let {onlyRunIfActive, onlyRunIfChanged} = options;
if ((onlyRunIfActive && !this.model.active) || !findPattern) return Promise.resolve();

return this.showResultPane().then(() => {
try {
return this.model.search(findPattern, pathsPattern, replacePattern, options);
} catch (e) {
this.setErrorMessage(e.message);
}
});
await this.showResultPane()

try {
return await this.model.search(findPattern, pathsPattern, replacePattern, options);
} catch (e) {
this.setErrorMessage(e.message);
}
}

replaceAll() {
Expand Down
23 changes: 12 additions & 11 deletions lib/project/results-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -236,17 +236,18 @@ module.exports = class ResultsModel {
})

this.emitter.emit('did-start-searching', this.inProgressSearchPromise)
return this.inProgressSearchPromise.then(message => {
if (message === 'cancelled') {
this.emitter.emit('did-cancel-searching')
} else {
const resultsSummary = this.getResultsSummary()

this.metricsReporter.sendSearchEvent(Date.now() - startTime, resultsSummary.matchCount)
this.inProgressSearchPromise = null
this.emitter.emit('did-finish-searching', resultsSummary)
}
})
const message = await this.inProgressSearchPromise

if (message === 'cancelled') {
this.emitter.emit('did-cancel-searching')
} else {
const resultsSummary = this.getResultsSummary()

this.metricsReporter.sendSearchEvent(Date.now() - startTime, resultsSummary.matchCount)
this.inProgressSearchPromise = null
this.emitter.emit('did-finish-searching', resultsSummary)
}
}

replace (pathsPattern, replacePattern, replacementPaths) {
Expand Down

0 comments on commit e2600aa

Please sign in to comment.