Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove empty arguments from launcher #1650

Merged
merged 4 commits into from
Feb 18, 2020

Conversation

purkhusid
Copy link
Contributor

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Currently the launcher script adds a empty argument to the end of all invocations.
Some programs do not like it and fail. An example is grpc_tools_node_protoc_plugin in the grpc-tools NPM package.

What is the new behavior?

If the argument list is empty we don't add an empty argument when invoking programs

Does this PR introduce a breaking change?

  • Yes
  • No

Copy link
Collaborator

@gregmagolan gregmagolan left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Can you also add a test case until internal/node/test that fails without this fix so we prevent regression in the future?

@@ -224,13 +224,28 @@ if [ "${EXPECTED_EXIT_CODE}" -eq "0" ]; then
# handled by the node process.
# If we had merely forked a child process here, we'd be responsible
# for forwarding those OS interactions.
exec "${node}" "${LAUNCHER_NODE_OPTIONS[@]:-}" "${USER_NODE_OPTIONS[@]:-}" "${MAIN}" "${ARGS[@]:-}"
if (( ${#ARGS[@]} )); then
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe if (( ${#ARGS} )); then is equivalent and sufficient here.

The duplication is not great. How about something like:

command="${node}" "${LAUNCHER_NODE_OPTIONS[@]:-}" "${USER_NODE_OPTIONS[@]:-}" "${MAIN}"
# If there are no arguments we skip the arguments because some programs
# such as grpc_tools_node_protoc_plugin in the grpc-tools do not handle empty arguments well
if (( ${#ARGS} )); then
  command="${command}" "${ARGS[@]:-}"
fi
exec "${command}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a issue with using set -u and empty arrays with older versions of bash.
See more information here: https://stackoverflow.com/questions/7577052/bash-empty-array-expansion-with-set-u

@purkhusid
Copy link
Contributor Author

purkhusid commented Feb 18, 2020

@gregmagolan Added a test

Copy link
Collaborator

@gregmagolan gregmagolan left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for simplification & adding the regression test.
Will green up that flake and merge.

@@ -224,12 +224,12 @@ if [ "${EXPECTED_EXIT_CODE}" -eq "0" ]; then
# handled by the node process.
# If we had merely forked a child process here, we'd be responsible
# for forwarding those OS interactions.
exec "${node}" "${LAUNCHER_NODE_OPTIONS[@]:-}" "${USER_NODE_OPTIONS[@]:-}" "${MAIN}" "${ARGS[@]:-}"
exec "${node}" "${LAUNCHER_NODE_OPTIONS[@]:-}" "${USER_NODE_OPTIONS[@]:-}" "${MAIN}" ${ARGS[@]+"${ARGS[@]}"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's neat 👍 👍

name = "binary_with_no_arguments",
data = ["empty_args_fail.js"],
entry_point = "empty_args_fail.js",
expected_exit_code = 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: expected_exit_code = 0 is redundant


if (theArgs.length != 0) {
// Non-zero exit code if the argument list is not empty
process.exit(42)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I approve of the error code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants