Skip to content

Commit

Permalink
Merge pull request #590 from desktop/abortable-exec
Browse files Browse the repository at this point in the history
[Breaking] Allow aborting exec, remove execTask
  • Loading branch information
niik authored Oct 21, 2024
2 parents 4df7225 + c1cfd3d commit 0cad3e4
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 289 deletions.
19 changes: 8 additions & 11 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

`dugite` is a wrapper on top of the Git command line interface, with some helpers to make it easy to consume in your Node applications. The important parts:

- `GitProcess` - the core of the library - `GitProcess.exec` is how you
interact with Git
- `IGitResult` - the abstraction for a result returned by Git - contains
exit code and standard output/error text
- `IGitExecutionOptions` - additional overrides to change the behaviour
of `GitProcess` (see [API extensibility](./api-extensibility.md) for
more information)
- `GitError` - a collection of known error codes that `dugite` can understand
- `GitNotFoundErrorCode` and `RepositoryDoesNotExistErrorCode` - error codes
that `dugite` will raise for exceptional scenarios when invoking Git - you
should check for these in your code.
- `GitProcess` - the core of the library - `GitProcess.exec` is how you
interact with Git
- `IGitResult` - the abstraction for a result returned by Git - contains
exit code and standard output/error text
- `IGitExecutionOptions` - additional overrides to change the behaviour
of `GitProcess` (see [API extensibility](./api-extensibility.md) for
more information)
- `GitError` - a collection of known error codes that `dugite` can understand
51 changes: 44 additions & 7 deletions lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,48 @@ export const GitErrorRegexes: { [regexp: string]: GitError } = {
GitError.PathExistsButNotInRef,
}

/**
* The error code for when git cannot be found. This most likely indicates a
* problem with dugite itself.
*/
export const GitNotFoundErrorCode = 'git-not-found-error'
export class ExecError extends Error {
/**
* The error.code property is a string label that identifies the kind of error
*
* See https://nodejs.org/api/errors.html#errorcode
*/
public readonly code?: string

/** The error code for when the path to a repository doesn't exist. */
export const RepositoryDoesNotExistErrorCode = 'repository-does-not-exist-error'
/**
* The signal that terminated the process
*/
public readonly signal?: string

/**
* Whether the child process successfully received a signal from
* subprocess.kill(). The killed property does not indicate that the child
* process has been terminated.
*/
public readonly killed?: boolean

constructor(
public readonly message: string,
public readonly stdout: Buffer | string,
public readonly stderr: Buffer | string,
cause?: unknown
) {
super(message, { cause })

if (cause && typeof cause === 'object') {
if ('code' in cause) {
if (typeof cause.code === 'string') {
this.code = cause.code
}
}

if ('signal' in cause && typeof cause.signal === 'string') {
this.signal = cause.signal
}

if ('killed' in cause && typeof cause.killed === 'boolean') {
this.killed = cause.killed
}
}
}
}
Loading

0 comments on commit 0cad3e4

Please sign in to comment.