Skip to content

Commit 150cf30

Browse files
committed
fix: helpful error messages when runtime mismatch for build
1 parent 7708187 commit 150cf30

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

aws_lambda_builders/exceptions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ class UnsupportedManifestError(LambdaBuilderError):
1616

1717

1818
class MisMatchRuntimeError(LambdaBuilderError):
19-
MESSAGE = "A runtime version mismatch was found for the given language " \
20-
"'{language}', required runtime '{required_runtime}'"
19+
MESSAGE = "{language} executable found in your path does not " \
20+
"match runtime. " \
21+
"\n Expected version: {required_runtime}, Found version: {found_runtime}. " \
22+
"\n Consider moving {required_runtime} up path hierarchy." \
23+
"\n Possibly related: https://github.com/awslabs/aws-lambda-builders/issues/30"
2124

2225

2326
class WorkflowNotFoundError(LambdaBuilderError):

aws_lambda_builders/validate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def validate_python_cmd(required_language, required_runtime_version):
1717
"python",
1818
"-c",
1919
"import sys; "
20+
"sys.stdout.write('python' + str(sys.version_info.major) + '.' + str(sys.version_info.minor)); "
2021
"assert sys.version_info.major == {major} "
2122
"and sys.version_info.minor == {minor}".format(
2223
major=major,
@@ -63,10 +64,11 @@ def validate_runtime(cls, required_language, required_runtime):
6364
p = subprocess.Popen(cmd,
6465
cwd=os.getcwd(),
6566
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
66-
p.communicate()
67+
found_runtime, _ = p.communicate()
6768
if p.returncode != 0:
6869
raise MisMatchRuntimeError(language=required_language,
69-
required_runtime=required_runtime)
70+
required_runtime=required_runtime,
71+
found_runtime=str(found_runtime.decode('utf-8')))
7072
else:
7173
LOG.warning("'%s' runtime has not "
7274
"been validated!", required_language)

tests/unit/test_runtime.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, returncode):
1313
self.returncode = returncode
1414

1515
def communicate(self):
16-
pass
16+
return b'python3,6', None
1717

1818

1919
class TestRuntime(TestCase):
@@ -44,6 +44,7 @@ def test_runtime_validate_mismatch_version_runtime(self):
4444

4545
def test_python_command(self):
4646
cmd = validate_python_cmd("python", "python2.7")
47-
version_strings = ["sys.version_info.major == 2", "sys.version_info.minor == 7"]
47+
version_strings = ["sys.stdout.write", "sys.version_info.major == 2",
48+
"sys.version_info.minor == 7"]
4849
for version_string in version_strings:
4950
self.assertTrue(any([part for part in cmd if version_string in part]))

0 commit comments

Comments
 (0)