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

Commit e2600aa

Browse files
committed
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
1 parent 04568a1 commit e2600aa

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

lib/project-find-view.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class ProjectFindView {
318318
return searchPromise;
319319
}
320320

321-
search(options) {
321+
async search(options) {
322322
// We always want to set the options passed in, even if we dont end up doing the search
323323
if (options == null) { options = {}; }
324324
this.model.getFindOptions().set(options);
@@ -330,13 +330,13 @@ class ProjectFindView {
330330
let {onlyRunIfActive, onlyRunIfChanged} = options;
331331
if ((onlyRunIfActive && !this.model.active) || !findPattern) return Promise.resolve();
332332

333-
return this.showResultPane().then(() => {
334-
try {
335-
return this.model.search(findPattern, pathsPattern, replacePattern, options);
336-
} catch (e) {
337-
this.setErrorMessage(e.message);
338-
}
339-
});
333+
await this.showResultPane()
334+
335+
try {
336+
return await this.model.search(findPattern, pathsPattern, replacePattern, options);
337+
} catch (e) {
338+
this.setErrorMessage(e.message);
339+
}
340340
}
341341

342342
replaceAll() {

lib/project/results-model.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ module.exports = class ResultsModel {
187187
)
188188
}
189189

190-
search (findPattern, pathsPattern, replacePattern, options = {}) {
190+
async search (findPattern, pathsPattern, replacePattern, options = {}) {
191191
if (!this.shouldRerunSearch(findPattern, pathsPattern, options)) {
192192
this.emitter.emit('did-noop-search')
193193
return Promise.resolve()
@@ -236,17 +236,18 @@ module.exports = class ResultsModel {
236236
})
237237

238238
this.emitter.emit('did-start-searching', this.inProgressSearchPromise)
239-
return this.inProgressSearchPromise.then(message => {
240-
if (message === 'cancelled') {
241-
this.emitter.emit('did-cancel-searching')
242-
} else {
243-
const resultsSummary = this.getResultsSummary()
244239

245-
this.metricsReporter.sendSearchEvent(Date.now() - startTime, resultsSummary.matchCount)
246-
this.inProgressSearchPromise = null
247-
this.emitter.emit('did-finish-searching', resultsSummary)
248-
}
249-
})
240+
const message = await this.inProgressSearchPromise
241+
242+
if (message === 'cancelled') {
243+
this.emitter.emit('did-cancel-searching')
244+
} else {
245+
const resultsSummary = this.getResultsSummary()
246+
247+
this.metricsReporter.sendSearchEvent(Date.now() - startTime, resultsSummary.matchCount)
248+
this.inProgressSearchPromise = null
249+
this.emitter.emit('did-finish-searching', resultsSummary)
250+
}
250251
}
251252

252253
replace (pathsPattern, replacePattern, replacementPaths) {

0 commit comments

Comments
 (0)