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

Solve bad trap prompt in generate.sh connector-template #5587

Closed
wants to merge 1 commit into from

Conversation

marcosmarxm
Copy link
Member

What

Closes #5586

How

Handle trap with EXIT and not ERR. Also, added --rm flag to handle when running the second time the connector-template.

Recommended reading order

  1. x.java
  2. y.python

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions
  • Connector added to connector index like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions
  • Connector version bumped like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

Connector Generator

  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed.

@marcosmarxm marcosmarxm changed the title Solve bad trap Solve bad trap prompt in generate.sh connector-template Aug 23, 2021
Copy link
Contributor

@airbyte-jenny airbyte-jenny left a comment

Choose a reason for hiding this comment

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

Trapping EXIT won't work right here.

@@ -3,7 +3,7 @@
error_handler() {
echo "While trying to generate a connector, an error occurred on line $1 of generate.sh and the process aborted early. This is probably a bug."
}
trap 'error_handler $LINENO' ERR
trap 'error_handler $LINENO' EXIT
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't do what you'd hope. ERR traps when the prior line was exit code nonzero. EXIT traps any time the script exits, including when it exits successfully with a zero exit code. That means the script can run completely fine and it'll still print the error message after, confusing the user. This has to stay ERR, or be refactored to use a different handling strategy entirely.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jennybrown8 is the suggestion made in this SO post a reasonable approach?

If my understanding of the problem is correct, the issue is that wherever this generate.sh script is getting run the ERR signal does not exist but EXIT does. So trapping exit but only emitting a non zero code upon checking the exit state solves the problem? Maybe there is a better way of doing this?

Very funny that this is a script that runs a docker container. We put the generation code in the docker container to avoid these portability issues... then sure enough the script has a portability issue. (@sherifnada you'll think this is funny)

Copy link
Contributor

@airbyte-jenny airbyte-jenny Aug 24, 2021

Choose a reason for hiding this comment

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

This PR doesn't say what problem it's trying to solve. What was the problem with ERR in the first place?
Oh, found it while digging into the linked issue:
"Try to run connector template got trap: ERR: bad trap. Users are complaining about this."

It's worth trying the stackoverflow suggestion. Do we have an environment where we can exactly reproduce their error? Working on macos, sh is symlinked to bash, so it doesn't behave the same as when run on a system with a real sh shell. This causes difficulty verifying solutions. Can we reproduce their error so we can assure that we've fixed it fully? The state of the code before I added a trap was that it silently fails when a subprocess fails, and the user thinks it succeeded but can't find the generated templates; that was also bad.

Copy link
Member Author

Choose a reason for hiding this comment

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

"Try to run connector template got trap: ERR: bad trap. Users are complaining about this."

I ran generate.sh on Ubuntu 20.04 and got the same problem as reported by user because of this I tried to suggest this modification. After the change I ran the script again and the ERR messages was gone. The script run correctly both ways, but with trap ERR the message is prompted to user.
Screenshot from 2021-08-24 20-56-54

Copy link
Contributor

Choose a reason for hiding this comment

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

Test it on macos as well. There, if you use trap EXIT, you'll see that after the script runs, and completes successfully, then it prints:

 While trying to generate a connector, an error occurred on line $1 of generate.sh and the process aborted early.  This is probably a bug.

That is, the trap function gets called when the script exits, even when the script succeeds. This is also confusing broken behavior, and not really a solution. We need a better answer, and to confirm that it works under both operating systems, and bash as well as sh.

@@ -21,7 +21,7 @@ docker build --build-arg UID="$_UID" --build-arg GID="$_GID" . -t airbyte/connec
# Run the container and mount the airbyte folder
if [ $# -eq 2 ]; then
echo "2 arguments supplied: 1=$1 2=$2"
docker run --name airbyte-connector-bootstrap --user $_UID:$_GID -e HOME=/tmp -e package_desc="$1" -e package_name="$2" -v "$(pwd)/../../../.":/airbyte airbyte/connector-bootstrap
docker run --rm --name airbyte-connector-bootstrap --user $_UID:$_GID -e HOME=/tmp -e package_desc="$1" -e package_name="$2" -v "$(pwd)/../../../.":/airbyte airbyte/connector-bootstrap
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fine.

@CLAassistant
Copy link

CLAassistant commented Sep 27, 2021

CLA assistant check
All committers have signed the CLA.

@marcosmarxm marcosmarxm closed this Dec 9, 2021
@noahkawasakigoogle
Copy link
Contributor

Is there a reason I'm not thinking of for why not fix it like this? #9243

@swyxio swyxio deleted the marcosmarx/bad-trap branch October 12, 2022 18:19
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.

connector-template bad trap
5 participants