Skip to content

Commit 362aa49

Browse files
author
Tjaž Eržen
authored
Merge pull request #13 from Codeplain-ai/feat/unrecoverable-exit-codes
Unrecoverable exit codes
2 parents e3585e5 + 36bc2ed commit 362aa49

9 files changed

Lines changed: 65 additions & 39 deletions

examples/example_hello_world_python/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CONFIG_FILE="config.yaml"
22
VERBOSE=0
33

44
# Check if verbose is set in config.yaml and set VERBOSE accordingly
5-
if grep -q "verbose: true" "$CONFIG_FILE" 2>/dev/null; then
5+
if grep -q "v: true" "$CONFIG_FILE" 2>/dev/null; then
66
VERBOSE=1
77
fi
88

plain2code.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
MAX_REFACTORING_ITERATIONS = 5
3737
MAX_UNIT_TEST_RENDER_RETRIES = 2
3838

39+
UNRECOVERABLE_ERROR_EXIT_CODES = [69]
40+
TIMEOUT_ERROR_EXIT_CODE = 124
41+
3942

4043
class InvalidFridArgument(Exception):
4144
pass
@@ -106,10 +109,7 @@ def execute_test_script(test_script, scripts_args, verbose, test_type):
106109
else:
107110
console.info(f"[b]All {test_type} tests passed successfully.[/b]\n")
108111

109-
# Return the output of the test script if it failed
110-
if result.returncode != 0:
111-
return result.stdout
112-
return None
112+
return result.returncode, result.stdout
113113
except subprocess.TimeoutExpired as e:
114114
# Store timeout output in a temporary file
115115
if verbose:
@@ -125,7 +125,7 @@ def execute_test_script(test_script, scripts_args, verbose, test_type):
125125
f"The {test_type} test timed out after {TEST_SCRIPT_EXECUTION_TIMEOUT} seconds. Test output stored in: {temp_file_path}\n"
126126
)
127127

128-
return f"Tests did not finish in {TEST_SCRIPT_EXECUTION_TIMEOUT} seconds."
128+
return TIMEOUT_ERROR_EXIT_CODE, f"Tests did not finish in {TEST_SCRIPT_EXECUTION_TIMEOUT} seconds."
129129

130130

131131
def run_unittests(
@@ -146,10 +146,17 @@ def run_unittests(
146146
if args.verbose:
147147
console.info(f"Running unit tests attempt {unit_test_run_count}.")
148148

149-
unittests_issue = execute_test_script(args.unittests_script, [args.build_folder], args.verbose, "unit")
149+
exit_code, unittests_issue = execute_test_script(
150+
args.unittests_script, [args.build_folder], args.verbose, "unit"
151+
)
150152

151-
if not unittests_issue:
153+
if exit_code == 0:
152154
return existing_files, changed_files, True
155+
elif exit_code in UNRECOVERABLE_ERROR_EXIT_CODES:
156+
console.error(unittests_issue)
157+
exit_with_error(
158+
"Unit tests script failed due to problems in the environment setup. Please check the your environment or update the script for running unittests.",
159+
)
153160

154161
existing_files_content = file_utils.get_existing_files_content(args.build_folder, existing_files)
155162

@@ -315,16 +322,22 @@ def run_conformance_tests( # noqa: C901
315322
f"\n[b]Running conformance tests script {args.conformance_tests_script} for {conformance_tests_folder_name} (functional requirement {functional_requirement_id}, attempt: {conformance_test_fix_count}).[/b]"
316323
)
317324

318-
conformance_tests_issue = execute_test_script(
325+
exit_code, conformance_tests_issue = execute_test_script(
319326
args.conformance_tests_script,
320327
[args.build_folder, conformance_tests_folder_name],
321328
args.verbose,
322329
"conformance",
323330
)
324331

325-
if not conformance_tests_issue:
332+
if exit_code == 0:
326333
break
327334

335+
elif exit_code in UNRECOVERABLE_ERROR_EXIT_CODES:
336+
console.error(conformance_tests_issue)
337+
exit_with_error(
338+
"Conformance tests script failed due to problems in the envronment setup. Please check the your environment or update the script for running conformance tests.",
339+
)
340+
328341
if conformance_test_fix_count > MAX_CONFORMANCE_TEST_FIX_ATTEMPTS:
329342
console.info(
330343
f"Conformance tests script {args.conformance_tests_script} for {conformance_tests_folder_name} still failed after {conformance_test_fix_count - 1} attempts at fixing issues."

plain2code_read_config.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import logging
21
import os
32
from argparse import ArgumentParser, Namespace
43
from typing import Any, Dict
54

65
import yaml
76

7+
from plain2code_console import console
8+
89

910
def load_config(config_file: str) -> Dict[str, Any]:
1011
"""Load configuration from YAML file."""
1112
try:
1213
with open(config_file, "r") as f:
1314
return yaml.safe_load(f)
1415
except Exception as e:
15-
logging.error(f"Error loading config file: {e}. Please check the config file path and the config file content.")
16-
raise
16+
console.error(f"Error loading config file: {e}. Please check the config file path and the config file content.")
17+
raise e
1718

1819

1920
def validate_config(config: Dict[str, Any], parser: ArgumentParser) -> None:
@@ -47,7 +48,7 @@ def get_args_from_config(config_file: str, parser: ArgumentParser) -> Namespace:
4748

4849
if config_file == "config.yaml":
4950
if not os.path.exists(config_file):
50-
logging.error(f"Default config file {config_file} not found. No config file is read.")
51+
console.info(f"Default config file {config_file} not found. No config file is read.")
5152
return args
5253

5354
# Load config

test_scripts/run_conformance_tests_cypress.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
UNRECOVERABLE_ERROR_EXIT_CODE=69
4+
35
NPM_INSTALL_OUTPUT_FILTER="up to date in|added [0-9]* packages, removed [0-9]* packages, and changed [0-9]* packages in|removed [0-9]* packages, and changed [0-9]* packages in|added [0-9]* packages in|removed [0-9]* packages in"
46

57
# Function to check and kill any Node process running on port 3000 (React development server)
@@ -44,7 +46,7 @@ cleanup() {
4446
if [ ! -z "${REACT_APP_PID+x}" ]; then
4547
local processes_to_kill=()
4648
get_children $REACT_APP_PID
47-
49+
4850
# Kill the main process
4951
kill $REACT_APP_PID 2>/dev/null
5052

@@ -73,14 +75,14 @@ check_and_kill_node_server
7375
if [ -z "$1" ]; then
7476
printf "Error: No build folder name provided.\n"
7577
printf "Usage: $0 <build_folder_name> <conformance_tests_folder>\n"
76-
exit 1
78+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
7779
fi
7880

7981
# Check if conformance tests folder name is provided
8082
if [ -z "$2" ]; then
8183
printf "Error: No conformance tests folder name provided.\n"
8284
printf "Usage: $0 <build_folder_name> <conformance_tests_folder>\n"
83-
exit 1
85+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
8486
fi
8587

8688
if [[ "$3" == "-v" || "$3" == "--verbose" ]]; then
@@ -107,7 +109,7 @@ fi
107109
if [ -d "$NODE_SUBFOLDER" ]; then
108110
# Find and delete all files and folders except "node_modules", "build", and "package-lock.json"
109111
find "$NODE_SUBFOLDER" -mindepth 1 ! -path "$NODE_SUBFOLDER/node_modules*" ! -path "$NODE_SUBFOLDER/build*" ! -name "package-lock.json" -exec rm -rf {} +
110-
112+
111113
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
112114
printf "Cleanup completed, keeping 'node_modules' and 'package-lock.json'.\n"
113115
fi
@@ -126,7 +128,7 @@ cd "$NODE_SUBFOLDER" 2>/dev/null
126128

127129
if [ $? -ne 0 ]; then
128130
printf "Error: Node build folder '$NODE_SUBFOLDER' does not exist.\n"
129-
exit 2
131+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
130132
fi
131133

132134
npm install --prefer-offline --no-audit --no-fund --loglevel error | grep -Ev "$NPM_INSTALL_OUTPUT_FILTER"
@@ -194,7 +196,7 @@ fi
194196
if [ -d "$NODE_CONFORMANCE_TESTS_SUBFOLDER" ]; then
195197
# Find and delete all files and folders except "node_modules", "build", and "package-lock.json"
196198
find "$NODE_CONFORMANCE_TESTS_SUBFOLDER" -mindepth 1 ! -path "$NODE_CONFORMANCE_TESTS_SUBFOLDER/node_modules*" ! -path "$NODE_CONFORMANCE_TESTS_SUBFOLDER/build*" ! -name "package-lock.json" -exec rm -rf {} +
197-
199+
198200
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
199201
printf "Cleanup completed, keeping 'node_modules' and 'package-lock.json'.\n"
200202
fi
@@ -213,7 +215,7 @@ cd "$NODE_CONFORMANCE_TESTS_SUBFOLDER" 2>/dev/null
213215

214216
if [ $? -ne 0 ]; then
215217
printf "Error: conformance tests Node folder '$NODE_CONFORMANCE_TESTS_SUBFOLDER' does not exist.\n"
216-
exit 2
218+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
217219
fi
218220

219221
npm install cypress --save-dev --prefer-offline --no-audit --no-fund --loglevel error | grep -Ev "$NPM_INSTALL_OUTPUT_FILTER"
@@ -229,5 +231,5 @@ if [ $cypress_run_result -ne 0 ]; then
229231
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
230232
printf "Error: Cypress conformance tests have failed.\n"
231233
fi
232-
exit 2
234+
exit 1
233235
fi

test_scripts/run_conformance_tests_golang.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/bin/bash
22

3+
UNRECOVERABLE_ERROR_EXIT_CODE=69
4+
35
# Check if build folder name is provided
46
if [ -z "$1" ]; then
57
printf "Error: No build folder name provided.\n"
68
printf "Usage: $0 <build_folder_name> <conformance_tests_folder>\n"
7-
exit 1
9+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
810
fi
911

1012
# Check if conformance tests folder name is provided
1113
if [ -z "$2" ]; then
1214
printf "Error: No conformance tests folder name provided.\n"
1315
printf "Usage: $0 <build_folder_name> <conformance_tests_folder>\n"
14-
exit 1
16+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
1517
fi
1618

1719
current_dir=$(pwd)
@@ -26,7 +28,7 @@ fi
2628
if [ -d "$GO_BUILD_SUBFOLDER" ]; then
2729
# Find and delete all files and folders
2830
find "$GO_BUILD_SUBFOLDER" -mindepth 1 -exec rm -rf {} +
29-
31+
3032
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
3133
printf "Cleanup completed.\n"
3234
fi
@@ -45,7 +47,7 @@ cd "$GO_BUILD_SUBFOLDER" 2>/dev/null
4547

4648
if [ $? -ne 0 ]; then
4749
printf "Error: Go build folder '$GO_BUILD_SUBFOLDER' does not exist.\n"
48-
exit 2
50+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
4951
fi
5052

5153
echo "Runinng go get in the build folder..."
@@ -55,7 +57,7 @@ cd "$current_dir/$2" 2>/dev/null
5557

5658
if [ $? -ne 0 ]; then
5759
printf "Error: Conformance tests folder '$current_dir/$2' does not exist.\n"
58-
exit 2
60+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
5961
fi
6062

6163
echo "Checking for go.mod in conformance test directory..."

test_scripts/run_conformance_tests_python.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#!/bin/bash
22

3+
UNRECOVERABLE_ERROR_EXIT_CODE=69
4+
35
# Check if build folder name is provided
46
if [ -z "$1" ]; then
57
printf "Error: No build folder name provided.\n"
68
printf "Usage: $0 <build_folder_name> <conformance_tests_folder>\n"
7-
exit 1
9+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
810
fi
911

1012
# Check if conformance tests folder name is provided
1113
if [ -z "$2" ]; then
1214
printf "Error: No conformance tests folder name provided.\n"
1315
printf "Usage: $0 <build_folder_name> <conformance_tests_folder>\n"
14-
exit 1
16+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
1517
fi
1618

1719
current_dir=$(pwd)
@@ -21,7 +23,7 @@ cd "$1" 2>/dev/null
2123

2224
if [ $? -ne 0 ]; then
2325
printf "Error: Build folder '$1' does not exist.\n"
24-
exit 2
26+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
2527
fi
2628

2729
# Execute all Python conformance tests in the build folder

test_scripts/run_unittests_golang.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717
if [ -d "$GO_BUILD_SUBFOLDER" ]; then
1818
# Find and delete all files and folders
1919
find "$GO_BUILD_SUBFOLDER" -mindepth 1 -exec rm -rf {} +
20-
20+
2121
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
2222
printf "Cleanup completed.\n"
2323
fi
@@ -39,7 +39,7 @@ if [ $? -ne 0 ]; then
3939
exit 2
4040
fi
4141

42-
echo "Runinng go get..."
42+
echo "Running go get..."
4343
go get
4444

4545
# Execute all Golang unittests in the subfolder

test_scripts/run_unittests_python.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
#!/bin/bash
22

3+
UNRECOVERABLE_ERROR_EXIT_CODE=69
4+
35
# Check if subfolder name is provided
46
if [ -z "$1" ]; then
57
echo "Error: No subfolder name provided."
68
echo "Usage: $0 <subfolder_name>"
7-
exit 1
9+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
810
fi
911

1012
# Move to the subfolder
1113
cd "$1" 2>/dev/null
1214

1315
if [ $? -ne 0 ]; then
1416
echo "Error: Subfolder '$1' does not exist."
15-
exit 2
17+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
1618
fi
1719

1820
# Execute all Python unittests in the subfolder
@@ -24,7 +26,7 @@ exit_code=$?
2426
# Check if the command timed out
2527
if [ $exit_code -eq 124 ]; then
2628
printf "\nError: Unittests timed out after 60 seconds.\n"
27-
exit 3
29+
exit $exit_code
2830
fi
2931

3032
# Echo the original output

test_scripts/run_unittests_react.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
UNRECOVERABLE_ERROR_EXIT_CODE=69
4+
35
# ANSI escape code pattern to remove color codes and formatting from output
46
ANSI_ESCAPE_PATTERN="s/\x1b\[[0-9;]*[mK]//g"
57

@@ -11,7 +13,7 @@ set -o pipefail
1113
if [ -z "$1" ]; then
1214
echo "Error: No subfolder name provided."
1315
echo "Usage: $0 <subfolder_name>"
14-
exit 1
16+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
1517
fi
1618

1719
# Define the path to the subfolder
@@ -25,7 +27,7 @@ fi
2527
if [ -d "$NODE_SUBFOLDER" ]; then
2628
# Find and delete all files and folders except "node_modules", "build", and "package-lock.json"
2729
find "$NODE_SUBFOLDER" -mindepth 1 ! -path "$NODE_SUBFOLDER/node_modules*" ! -path "$NODE_SUBFOLDER/build*" ! -name "package-lock.json" -exec rm -rf {} +
28-
30+
2931
if [ "${VERBOSE:-}" -eq 1 ] 2>/dev/null; then
3032
printf "Cleanup completed, keeping 'node_modules' and 'package-lock.json'.\n"
3133
fi
@@ -44,7 +46,7 @@ cd "$NODE_SUBFOLDER" 2>/dev/null
4446

4547
if [ $? -ne 0 ]; then
4648
echo "Error: Subfolder '$1' does not exist."
47-
exit 2
49+
exit $UNRECOVERABLE_ERROR_EXIT_CODE
4850
fi
4951

5052
# Install libraries
@@ -59,4 +61,6 @@ TEST_EXIT_CODE=$?
5961
if [ $TEST_EXIT_CODE -ne 0 ]; then
6062
echo "Error: Tests failed with exit code $TEST_EXIT_CODE"
6163
exit $TEST_EXIT_CODE
62-
fi
64+
fi
65+
66+
exit $UNRECOVERABLE_ERROR_EXIT_CODE

0 commit comments

Comments
 (0)