Skip to content

Commit

Permalink
progress: replace execa with ejeca
Browse files Browse the repository at this point in the history
Summary: See D65138584 for more context about what ejeca is

Reviewed By: evangrayk

Differential Revision: D65138587

fbshipit-source-id: aacfe9ee137b5001cbc10aa5a4a912238eddb98a
  • Loading branch information
sggutier authored and facebook-github-bot committed Nov 18, 2024
1 parent cfeb4da commit ca7156d
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 103 deletions.
28 changes: 14 additions & 14 deletions addons/isl-server/src/Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {KindOfChange, PollKind} from './WatchForChanges';
import type {TrackEventName} from './analytics/eventNames';
import type {ConfigLevel, ResolveCommandConflictOutput} from './commands';
import type {RepositoryContext} from './serverTypes';
import type {ExecaError} from 'execa';
import type {
CommitInfo,
Disposable,
Expand Down Expand Up @@ -41,6 +40,7 @@ import type {
CwdInfo,
} from 'isl/src/types';
import type {Comparison} from 'shared/Comparison';
import type {EjecaOptions, EjecaError} from 'shared/ejeca';

import {Internal} from './Internal';
import {OperationQueue} from './OperationQueue';
Expand Down Expand Up @@ -76,10 +76,9 @@ import {
import {
findPublicAncestor,
handleAbortSignalOnProcess,
isExecaError,
isEjecaError,
serializeAsyncCall,
} from './utils';
import execa from 'execa';
import {
settableConfigNames,
allConfigNames,
Expand All @@ -92,6 +91,7 @@ import {revsetArgsForComparison} from 'shared/Comparison';
import {LRU} from 'shared/LRU';
import {RateLimiter} from 'shared/RateLimiter';
import {TypedEventEmitter} from 'shared/TypedEventEmitter';
import {ejeca} from 'shared/ejeca';
import {exists} from 'shared/fs';
import {removeLeadingPathSep} from 'shared/pathUtils';
import {notEmpty, randomId, nullthrows} from 'shared/utils';
Expand Down Expand Up @@ -689,7 +689,7 @@ export class Repository {
throw new Error(`command "${args.join(' ')}" is not allowed`);
}

const execution = execa(command, args, options);
const execution = ejeca(command, args, options);
// It would be more appropriate to call this in reponse to execution.on('spawn'), but
// this seems to be inconsistent about firing in all versions of node.
// Just send spawn immediately. Errors during spawn like ENOENT will still be reported by `exit`.
Expand All @@ -708,7 +708,7 @@ export class Repository {
const result = await execution;
onProgress('exit', result.exitCode || 0);
} catch (err) {
onProgress('exit', isExecaError(err) ? err.exitCode : -1);
onProgress('exit', isEjecaError(err) ? err.exitCode : -1);
throw err;
}
}
Expand Down Expand Up @@ -789,7 +789,7 @@ export class Repository {
this.uncommittedChangesEmitter.emit('change', this.uncommittedChanges);
} catch (err) {
let error = err;
if (isExecaError(error)) {
if (isEjecaError(error)) {
if (error.stderr.includes('checkout is currently in progress')) {
this.initialConnectionContext.logger.info(
'Ignoring `sl status` error caused by in-progress checkout',
Expand All @@ -799,8 +799,8 @@ export class Repository {
}

this.initialConnectionContext.logger.error('Error fetching files: ', error);
if (isExecaError(error)) {
error = simplifyExecaError(error);
if (isEjecaError(error)) {
error = simplifyEjecaError(error);
}

// emit an error, but don't save it to this.uncommittedChanges
Expand Down Expand Up @@ -895,13 +895,13 @@ export class Repository {
if (internalError) {
error = internalError;
}
if (isExecaError(error) && error.stderr.includes('Please check your internet connection')) {
if (isEjecaError(error) && error.stderr.includes('Please check your internet connection')) {
error = Error('Network request failed. Please check your internet connection.');
}

this.initialConnectionContext.logger.error('Error fetching commits: ', error);
if (isExecaError(error)) {
error = simplifyExecaError(error);
if (isEjecaError(error)) {
error = simplifyEjecaError(error);
}

this.smartlogCommitsChangesEmitter.emit('change', {
Expand Down Expand Up @@ -1373,7 +1373,7 @@ export class Repository {
/** Which event name to track for this command. If undefined, generic 'RunCommand' is used. */
eventName: TrackEventName | undefined,
ctx: RepositoryContext,
options?: execa.Options,
options?: EjecaOptions,
timeout?: number,
) {
const id = randomId();
Expand Down Expand Up @@ -1508,8 +1508,8 @@ function isUnhealthyEdenFs(cwd: string): Promise<boolean> {
}

/**
* Extract the actually useful stderr part of the Execa Error, to avoid the long command args being printed first.
* Extract the actually useful stderr part of the Ejeca Error, to avoid the long command args being printed first.
* */
function simplifyExecaError(error: ExecaError): Error {
function simplifyEjecaError(error: EjecaError): Error {
return new Error(error.stderr.trim() || error.message);
}
4 changes: 2 additions & 2 deletions addons/isl-server/src/ServerToClientAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {ServerSideTracker} from './analytics/serverSideTracker';
import type {Logger} from './logger';
import type {ServerPlatform} from './serverPlatform';
import type {RepositoryContext} from './serverTypes';
import type {ExecaError} from 'execa';
import type {TypeaheadResult} from 'isl-components/Types';
import type {Serializable} from 'isl/src/serialize';
import type {
Expand All @@ -29,6 +28,7 @@ import type {
CodeReviewProviderSpecificClientToServerMessages,
StableLocationData,
} from 'isl/src/types';
import type {EjecaError} from 'shared/ejeca';
import type {ExportStack, ImportedStack} from 'shared/types/stack';

import {generatedFilesDetector} from './GeneratedFiles';
Expand Down Expand Up @@ -963,7 +963,7 @@ export default class ServerToClientAPI {
url: {value: result.stdout},
});
})
.catch((err: ExecaError) => {
.catch((err: EjecaError) => {
this.logger.error('Failed to get repo url at hash:', err);
this.postMessage({
type: 'gotRepoUrlAtHash',
Expand Down
Loading

0 comments on commit ca7156d

Please sign in to comment.