Skip to content

Commit f70aebe

Browse files
committed
Improved exception catch for docker
1 parent 9e553c7 commit f70aebe

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

docker/run_python.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
retcode=0
44
ping_url="https://api.rosette.com/rest/v1"
5+
errors=( "Exception" "processingFailure" "badRequest" "ParseError" "ValueError" "SyntaxError" "AttributeError" "ImportError" )
56

67
#------------------ Functions ----------------------------------------------------
78
#Gets called when the user doesn't provide any args
@@ -14,6 +15,10 @@ function HELP {
1415
exit 1
1516
}
1617

18+
if [ ! -z ${ALT_URL} ]; then
19+
ping_url=${ALT_URL}
20+
fi
21+
1722
#Checks if Rosette API key is valid
1823
function checkAPI {
1924
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
@@ -53,16 +58,11 @@ function runExample() {
5358
fi
5459
echo "${result}"
5560
echo -e "\n---------- ${1} end -------------"
56-
if [[ "${result}" == *"Exception"* ]]; then
57-
echo "Exception found"
58-
retcode=1
59-
elif [[ "$result" == *"processingFailure"* ]]; then
60-
retcode=1
61-
elif [[ "$result" == *"AttributeError"* ]]; then
62-
retcode=1
63-
elif [[ "$result" == *"ImportError"* ]]; then
64-
retcode=1
65-
fi
61+
for err in "${errors[@]}"; do
62+
if [[ ${result} == *"${err}"* ]]; then
63+
retcode=1
64+
fi
65+
done
6666
}
6767
#------------------ Functions End ------------------------------------------------
6868

@@ -96,8 +96,10 @@ if [ ! -z ${API_KEY} ]; then
9696
python /python-dev/setup.py install
9797
cd /python-dev/examples
9898
if [ ! -z ${FILENAME} ]; then
99+
echo -e "\nRunning example against: ${ping_url}\n"
99100
runExample ${FILENAME}
100101
else
102+
echo -e "\nRunning examples against: ${ping_url}\n"
101103
for file in *.py; do
102104
runExample ${file}
103105
done

examples/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ RUN chmod 755 /python/examples/run_python.sh
1010
WORKDIR /python/examples
1111

1212
# allow interactive bash inside docker container
13-
CMD ./run_python.sh $API_KEY $FILENAME $ALT_URL
13+
CMD ./run_python.sh
1414

1515
VOLUME ["/source"]

examples/docker/run_python.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
retcode=0
44
ping_url="https://api.rosette.com/rest/v1"
5+
errors=( "Exception" "processingFailure" "badRequest" "ParseError" "ValueError" "SyntaxError" "AttributeError" "ImportError" )
56

67
#------------------ Functions ----------------------------------------------------
78

@@ -15,6 +16,10 @@ function HELP {
1516
exit 1
1617
}
1718

19+
if [ ! -z ${ALT_URL} ]; then
20+
ping_url=${ALT_URL}
21+
fi
22+
1823
#Checks if Rosette API key is valid
1924
function checkAPI() {
2025
match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden")
@@ -54,16 +59,11 @@ function runExample() {
5459
fi
5560
echo "${result}"
5661
echo -e "\n---------- ${1} end -------------"
57-
if [[ "${result}" == *"Exception"* ]]; then
58-
echo "Exception found"
59-
retcode=1
60-
elif [[ "$result" == *"processingFailure"* ]]; then
61-
retcode=1
62-
elif [[ "$result" == *"AttributeError"* ]]; then
63-
retcode=1
64-
elif [[ "$result" == *"ImportError"* ]]; then
65-
retcode=1
66-
fi
62+
for err in "${errors[@]}"; do
63+
if [[ ${result} == *"${err}"* ]]; then
64+
retcode=1
65+
fi
66+
done
6767
}
6868

6969
#------------------ Functions End ------------------------------------------------
@@ -97,8 +97,10 @@ cp /source/examples/*.* .
9797
if [ ! -z ${API_KEY} ]; then
9898
checkAPI
9999
if [ ! -z ${FILENAME} ]; then
100+
echo -e "\nRunning example against: ${ping_url}\n"
100101
runExample ${FILENAME}
101102
else
103+
echo -e "\nRunning examples against: ${ping_url}\n"
102104
for file in *.py; do
103105
runExample ${file}
104106
done

0 commit comments

Comments
 (0)