Skip to content

Commit

Permalink
Address #34434 - don't fail when ripgrep exits with 1 and no stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Sep 15, 2017
1 parent 0144724 commit ae2accf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/vs/workbench/services/search/node/fileSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class FileWalker {
cmd = this.spawnFindCmd(folderQuery);
}

this.collectStdout(cmd, 'utf8', (err: Error, stdout?: string, last?: boolean) => {
this.collectStdout(cmd, 'utf8', useRipgrep, (err: Error, stdout?: string, last?: boolean) => {
if (err) {
done(err);
return;
Expand Down Expand Up @@ -354,9 +354,9 @@ export class FileWalker {
/**
* Public for testing.
*/
public readStdout(cmd: childProcess.ChildProcess, encoding: string, cb: (err: Error, stdout?: string) => void): void {
public readStdout(cmd: childProcess.ChildProcess, encoding: string, isRipgrep: boolean, cb: (err: Error, stdout?: string) => void): void {
let all = '';
this.collectStdout(cmd, encoding, (err: Error, stdout?: string, last?: boolean) => {
this.collectStdout(cmd, encoding, isRipgrep, (err: Error, stdout?: string, last?: boolean) => {
if (err) {
cb(err);
return;
Expand All @@ -369,7 +369,7 @@ export class FileWalker {
});
}

private collectStdout(cmd: childProcess.ChildProcess, encoding: string, cb: (err: Error, stdout?: string, last?: boolean) => void): void {
private collectStdout(cmd: childProcess.ChildProcess, encoding: string, isRipgrep: boolean, cb: (err: Error, stdout?: string, last?: boolean) => void): void {
let done = (err: Error, stdout?: string, last?: boolean) => {
if (err || last) {
done = () => { };
Expand All @@ -386,7 +386,8 @@ export class FileWalker {
});

cmd.on('close', (code: number) => {
if (code !== 0) {
// ripgrep returns code=1 when no results are found
if (code !== 0 && ((isRipgrep && stderr.length) || !isRipgrep)) {
done(new Error(`command failed with error code ${code}: ${this.decodeData(stderr, encoding)}`));
} else {
done(null, '', true);
Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/services/search/node/ripgrepTextSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ function globExprsToRgGlobs(patterns: glob.IExpression, folder?: string, exclude
return;
}

if (!key) {
return;
}

const value = patterns[key];
key = trimTrailingSlash(folder ? getAbsoluteGlob(folder, key) : key);

Expand Down

0 comments on commit ae2accf

Please sign in to comment.