Skip to content

Conversation

@Hweinstock
Copy link
Contributor

@Hweinstock Hweinstock commented Nov 27, 2024

Problem

contributors may use the low-level node child_process library, which lacks the instrumentation and robustness of the toolkit ChildProcess utility.

Example: #5925 (comment)

Solution

  • add the node child_process library as a "banned import" with a message pointing to our ChildProcess utility.
  • Migrate simple cases to use our ChildProcess, mark more complex ones as exceptions.

Future Work

  • To migrate the existing cases marked as exceptions, we will need to add functionality to our ChildProcess api, such as enforcing a maxBufferSize on the output.
  • Additionally, some of the current uses of child_process are tied to implementation details in the child_process library that make it hard to change without a larger-scale refactor. These cases were marked as exceptions.

License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@Hweinstock Hweinstock marked this pull request as ready for review November 29, 2024 17:21
@Hweinstock Hweinstock requested review from a team as code owners November 29, 2024 17:21
Comment on lines 192 to 194
const goPath: string = JSON.parse(
(await ChildProcess.exec('go', ['env', '-json'], { collect: true })).stdout
).GOPATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a local var is a bit more terse and readable, at the cost of having to claim a name.
But generally, invoking a process almost always should involve checking an exit code (though that's out of scope for this PR), so inlining exec() or run() is unusual and likely discouraged. .

Suggested change
const goPath: string = JSON.parse(
(await ChildProcess.exec('go', ['env', '-json'], { collect: true })).stdout
).GOPATH
const r = await ChildProcess.exec('go', ['env', '-json'], { collect: true })
const goPath: string = JSON.parse(r.stdout).GOPATH

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally checking the exit code would be part of some higher-level API provided by ChildProcess right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally checking the exit code would be part of some higher-level API provided by ChildProcess right?

Failure handling in some way needs to be done by the caller, typically

@justinmk3
Copy link
Contributor

This is good to have in place. We don't need to bother migrating any of the child_process cases for Q features, since most of those will use Flare.

@justinmk3 justinmk3 merged commit d682314 into aws:master Dec 12, 2024
18 of 28 checks passed
@Hweinstock Hweinstock deleted the lint/noCP branch December 24, 2024 16:46
karanA-aws pushed a commit to karanA-aws/aws-toolkit-vscode that referenced this pull request Jan 17, 2025
…aws#6113

## Problem
contributors may use the low-level node `child_process` library, which
lacks the instrumentation and robustness of the toolkit `ChildProcess`
utility.
Example:
aws#5925 (comment)

## Solution
- add the node `child_process` library as a "banned import" with a
message pointing to our `ChildProcess` utility.
- Migrate simple cases to use our `ChildProcess`, mark more complex ones
as exceptions.

## Future Work
- To migrate the existing cases marked as exceptions, we will need to
add functionality to our `ChildProcess` api, such as enforcing a
`maxBufferSize` on the output.
- Additionally, some of the current uses of `child_process` are tied to
implementation details in the `child_process` library that make it hard
to change without a larger-scale refactor. These cases were marked as
exceptions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants