Skip to content

fix(unzip): replace UserException with ValueError exception in _extract()#8599

Merged
vicheey merged 2 commits intodevelopfrom
fix-test-run
Jan 27, 2026
Merged

fix(unzip): replace UserException with ValueError exception in _extract()#8599
vicheey merged 2 commits intodevelopfrom
fix-test-run

Conversation

@vicheey
Copy link
Copy Markdown
Contributor

@vicheey vicheey commented Jan 27, 2026

Which issue(s) does this change fix?

  • Fixes Terraform integration test failures with ModuleNotFoundError: No module named 'samcli'
  • Also, add tmp folder generated during integration test run in .gitignore

Why is this change necessary?

During Terraform builds, SAM CLI copies zip.py from samcli/local/lambdafn/ to an isolated temporary directory (.aws-sam-iacs/iacs_metadata/) where it's executed as part of the build process. The original code imported UserException from samcli.commands.exceptions, but the samcli package is not available in this isolated directory, causing the import to fail with ModuleNotFoundError.

How does it address the issue?

This change replaces the custom UserException with Python's built-in ValueError exception in the _extract function within samcli/local/lambdafn/zip.py. This eliminates the dependency on SAM CLI's internal module structure, making zip.py self-contained and able to run successfully when copied to the isolated metadata directory. The error handling behavior remains functionally equivalent.

  • File: samcli/hook_packages/terraform/hooks/prepare/makefile_generator.py (lines 96-97)
ZIP_UTILS_MODULE_script_path = os.path.join(samcli_root_path, "local", "lambdafn", ZIP_UTILS_MODULE)
shutil.copy(ZIP_UTILS_MODULE_script_path, output_directory_path)

Mandatory Checklist

PRs will only be reviewed after checklist is complete

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@vicheey vicheey changed the title fix(unzip): replace fix(unzip): replace UserException with ValueError exception in _extract() Jan 27, 2026
@vicheey vicheey force-pushed the fix-test-run branch 2 times, most recently from 0c98d41 to 3c594f6 Compare January 27, 2026 22:23
@vicheey vicheey marked this pull request as ready for review January 27, 2026 22:27
@vicheey vicheey requested a review from a team as a code owner January 27, 2026 22:27
@vicheey vicheey requested a review from valerena January 27, 2026 22:38
@vicheey vicheey added this pull request to the merge queue Jan 27, 2026
Merged via the queue into develop with commit 411e183 Jan 27, 2026
42 checks passed
@vicheey vicheey deleted the fix-test-run branch January 27, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants