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

Log errors from worker

上级 27f6824c
...@@ -12,6 +12,7 @@ import * as path from 'path'; ...@@ -12,6 +12,7 @@ import * as path from 'path';
import * as ipc from 'vs/base/parts/ipc/common/ipc'; 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 { IProgress } from 'vs/platform/search/common/search';
import { FileWalker } from 'vs/workbench/services/search/node/fileSearch'; import { FileWalker } from 'vs/workbench/services/search/node/fileSearch';
import { ISerializedFileMatch, ISerializedSearchComplete, IRawSearch, ISearchEngine } from './search'; import { ISerializedFileMatch, ISerializedSearchComplete, IRawSearch, ISearchEngine } from './search';
...@@ -49,7 +50,10 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> { ...@@ -49,7 +50,10 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> {
this.isCanceled = true; this.isCanceled = true;
this.walker.cancel(); 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 { 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> { ...@@ -102,7 +106,12 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> {
} }
unwind(batchBytes); 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 // Walk over the file system
...@@ -170,7 +179,7 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> { ...@@ -170,7 +179,7 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> {
const channel = ipc.getNextTickChannel(client.getChannel<ISearchWorkerChannel>('searchWorker')); const channel = ipc.getNextTickChannel(client.getChannel<ISearchWorkerChannel>('searchWorker'));
const channelClient = new SearchWorkerChannelClient(channel); const channelClient = new SearchWorkerChannelClient(channel);
const config: ISearchWorkerConfig = { pattern: this.config.contentPattern, id, fileEncoding: this.config.fileEncoding }; 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.workers.push(channelClient);
this.workerClients.push(client); this.workerClients.push(client);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import * as fs from 'fs'; import * as fs from 'fs';
import { onUnexpectedError } from 'vs/base/common/errors';
import * as strings from 'vs/base/common/strings'; import * as strings from 'vs/base/common/strings';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { ISerializedFileMatch } from '../search'; import { ISerializedFileMatch } from '../search';
...@@ -25,6 +26,14 @@ interface ReadLinesOptions { ...@@ -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. // Global isCanceled flag for the process. It's only set once and this avoids awkwardness in passing it around.
let isCanceled = false; 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 { export class SearchWorker implements ISearchWorker {
static CONCURRENT_SEARCH_PATHS = 2; static CONCURRENT_SEARCH_PATHS = 2;
...@@ -89,7 +98,7 @@ function searchBatch(absolutePaths: string[], contentPattern: RegExp, fileEncodi ...@@ -89,7 +98,7 @@ function searchBatch(absolutePaths: string[], contentPattern: RegExp, fileEncodi
if (absolutePaths.length) { if (absolutePaths.length) {
return startSearchInFile(absolutePaths.shift()); return startSearchInFile(absolutePaths.shift());
} }
}); }, onError);
}; };
let batchPromises: TPromise<void>[] = []; let batchPromises: TPromise<void>[] = [];
......
...@@ -47,7 +47,7 @@ export class SearchWorkerChannel implements ISearchWorkerChannel { ...@@ -47,7 +47,7 @@ export class SearchWorkerChannel implements ISearchWorkerChannel {
call(command: string, arg?: any): TPromise<any> { call(command: string, arg?: any): TPromise<any> {
switch (command) { 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 'search': return this.worker.search(arg);
case 'cancel': return this.worker.cancel(); case 'cancel': return this.worker.cancel();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册