-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine.
Is there a reason I'm not thinking of for why not fix it like this? #9243 |
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
x.java
y.python
Pre-merge Checklist
Expand the relevant checklist and delete the others.
New Connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
docs/SUMMARY.md
docs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampledocs/integrations/README.md
airbyte-integrations/builds.md
Airbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing./publish
command described hereUpdating a connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
docs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampleAirbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing./publish
command described hereConnector Generator
-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