提交 7e577073 编写于 作者: R roblou

Log errors from worker

上级 27f6824c
......@@ -12,6 +12,7 @@ import * as path from 'path';
import * as ipc from 'vs/base/parts/ipc/common/ipc';
import { onUnexpectedError } from 'vs/base/common/errors';
import { IProgress } from 'vs/platform/search/common/search';
import { FileWalker } from 'vs/workbench/services/search/node/fileSearch';
import { ISerializedFileMatch, ISerializedSearchComplete, IRawSearch, ISearchEngine } from './search';
......@@ -49,7 +50,10 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> {
this.isCanceled = true;
this.walker.cancel();
this.workers.forEach(w => w.cancel());
this.workers.forEach(w => {
w.cancel()
.then(null, onUnexpectedError);
});
}
search(onResult: (match: ISerializedFileMatch) => void, onProgress: (progress: IProgress) => void, done: (error: Error, complete: ISerializedSearchComplete) => void): void {
......@@ -102,7 +106,12 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> {
}
unwind(batchBytes);
});
},
error => {
// An error on the worker's end, not in reading the file, but in processing the batch. Log and continue.
onUnexpectedError(error);
unwind(batchBytes);
});
};
// Walk over the file system
......@@ -170,7 +179,7 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> {
const channel = ipc.getNextTickChannel(client.getChannel<ISearchWorkerChannel>('searchWorker'));
const channelClient = new SearchWorkerChannelClient(channel);
const config: ISearchWorkerConfig = { pattern: this.config.contentPattern, id, fileEncoding: this.config.fileEncoding };
channelClient.initialize(config);
channelClient.initialize(config).then(null, onUnexpectedError);
this.workers.push(channelClient);
this.workerClients.push(client);
......
......@@ -7,6 +7,7 @@
import * as fs from 'fs';
import { onUnexpectedError } from 'vs/base/common/errors';
import * as strings from 'vs/base/common/strings';
import { TPromise } from 'vs/base/common/winjs.base';
import { ISerializedFileMatch } from '../search';
......@@ -25,6 +26,14 @@ interface ReadLinesOptions {
// Global isCanceled flag for the process. It's only set once and this avoids awkwardness in passing it around.
let isCanceled = false;
const MAX_FILE_ERRORS = 5; // Don't report more than this number of errors, 1 per file, to avoid flooding the log when there's a general issue
let numErrorsLogged = 0;
function onError(error: any): void {
if (numErrorsLogged++ < MAX_FILE_ERRORS) {
onUnexpectedError(error);
}
}
export class SearchWorker implements ISearchWorker {
static CONCURRENT_SEARCH_PATHS = 2;
......@@ -89,7 +98,7 @@ function searchBatch(absolutePaths: string[], contentPattern: RegExp, fileEncodi
if (absolutePaths.length) {
return startSearchInFile(absolutePaths.shift());
}
});
}, onError);
};
let batchPromises: TPromise<void>[] = [];
......
......@@ -47,7 +47,7 @@ export class SearchWorkerChannel implements ISearchWorkerChannel {
call(command: string, arg?: any): TPromise<any> {
switch (command) {
case 'initialize': return TPromise.wrap(this.worker.initialize(arg));
case 'initialize': return this.worker.initialize(arg);
case 'search': return this.worker.search(arg);
case 'cancel': return this.worker.cancel();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册