Skip to content

Commit

Permalink
fix(git): increase max proc buffer size and fix error handling (#5916)
Browse files Browse the repository at this point in the history
* fix(git): increase max buffer size  back to 100MB

* refactor: use named interface as a param object

* fix: detect `ExecaError`s properly

* chore: linting

* fix: stricter condition to check the exit code existence
  • Loading branch information
vvagaytsev committed Apr 9, 2024
1 parent ff5d57d commit 30fd9c0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions core/src/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { constants } from "os"
import dns from "node:dns"
import { styles } from "./logger/styles.js"
import type { ObjectPath } from "./config/base.js"
import type { ExecaError } from "execa"

// Unfortunately, NodeJS does not provide a list of all error codes, so we have to maintain this list manually.
// See https://nodejs.org/docs/latest-v18.x/api/dns.html#error-codes
Expand Down Expand Up @@ -75,6 +76,10 @@ export function isEAddrInUseException(err: any): err is EAddrInUseException {
return isErrnoException(err) && err.code === "EADDRINUSE"
}

export function isExecaError(err: any): err is ExecaError {
return err.exitCode !== undefined && err.exitCode !== null
}

export type StackTraceMetadata = {
functionName: string
relativeFileName?: string
Expand Down
25 changes: 15 additions & 10 deletions core/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
ChildProcessError,
InternalError,
isErrnoException,
isExecaError,
ParameterError,
RuntimeError,
TimeoutError,
Expand All @@ -43,7 +44,7 @@ import type { Log } from "../logger/log-entry.js"
import { getDefaultProfiler } from "./profiling.js"
import { dedent, naturalList, tailString } from "./string.js"
import split2 from "split2"
import type { ExecaError, Options as ExecaOptions } from "execa"
import type { Options as ExecaOptions } from "execa"
import { execa } from "execa"
import corePackageJson from "../../package.json" assert { type: "json" }
import { makeDocsLinkStyled } from "../docs/common.js"
Expand Down Expand Up @@ -208,15 +209,19 @@ export async function exec(cmd: string, args: string[], opts: ExecOpts = {}) {
})
}

const error = <ExecaError>err
throw new ChildProcessError({
cmd,
args,
code: error.exitCode,
output: error.all || error.stdout || error.stderr || "",
stderr: error.stderr || "",
stdout: error.stdout || "",
})
if (isExecaError(err)) {
throw new ChildProcessError({
cmd,
args,
code: err.exitCode,
output: err.all || err.stdout || err.stderr || "",
stderr: err.stderr || "",
stdout: err.stdout || "",
})
}

const error = err as Error
throw new InternalError({ message: error.message })
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function gitCliExecutor({ log, cwd, failOnPrompt = false }: GitCliParams): GitCl
log.silly(`Calling git with args '${args.join(" ")}' in ${cwd}`)
const { stdout } = await exec("git", args, {
cwd,
maxBuffer: 10 * 1024 * 1024,
maxBuffer: 100 * 1024 * 1024,
env: failOnPrompt ? { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "true" } : undefined,
})
return stdout.split("\n").filter((line) => line.length > 0)
Expand Down
9 changes: 2 additions & 7 deletions core/src/vcs/vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export interface GetTreeVersionParams {
projectName: string
config: ModuleConfig | BaseActionConfig
scanRoot?: string // Set the scanning root instead of detecting, in order to optimize the scanning.
force?: boolean
}

export interface RemoteSourceParams {
Expand Down Expand Up @@ -205,13 +206,7 @@ export abstract class VcsHandler {
config,
force = false,
scanRoot,
}: {
log: Log
projectName: string
config: ModuleConfig | BaseActionConfig
force?: boolean
scanRoot?: string
}): Promise<TreeVersion> {
}: GetTreeVersionParams): Promise<TreeVersion> {
const cacheKey = getResourceTreeCacheKey(config)
const description = describeConfig(config)

Expand Down

0 comments on commit 30fd9c0

Please sign in to comment.