Skip to content
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

Bug: sam build GoModulesBuilder fails to output the relevant error message, outputs "directory not found" instead #676

Open
distinctdan opened this issue Aug 14, 2024 · 3 comments

Comments

@distinctdan
Copy link

Description:

When my Go code has a syntax error, I expect sam build to display the error. Instead, it's showing a generic error:

Error: GoModulesBuilder:Build - Builder Failed: stat /Users/my.user/my-project/myproject/bootstrap: directory not found

In my template.yaml, here's the relevant block for my Go lambda:

Resources:
  MyFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Metadata:
      BuildMethod: go1.x
    Properties:
      CodeUri: myproject/
      Handler: bootstrap
      Runtime: provided.al2023
      Architectures:
        - x86_64

I have a file myproject/bootstrap.go that contains func main() { lambda.Start(handler) }.

Steps to reproduce:

Create any syntax error, like renaming a function from MyFunc to MyFunc2

Observed result:

A "directory not found" error.

Expected result:

The output from go build which shows the actual error.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: OSX Sonoma 14.6.1
  2. sam --version: SAM CLI, version 1.121.0
  3. AWS region: N/a
{
  "version": "1.121.0",
  "system": {
    "python": "3.8.13",
    "os": "macOS-14.6.1-x86_64-i386-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}
@distinctdan distinctdan added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Aug 14, 2024
@hawflau
Copy link
Contributor

hawflau commented Aug 15, 2024

@distinctdan thanks for raising the issue.
I could re-produce your issue. It seems to me that Lambda Builders does not check the status code when building the go package but instead just checks for the existence of the output binary. This is a bug we should fix.

@hawflau hawflau transferred this issue from aws/aws-sam-cli Aug 15, 2024
@hawflau hawflau added type/bug area/workflow/go_modules and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Aug 15, 2024
@keeve
Copy link

keeve commented Oct 9, 2024

I solved this by upgrading my Go version from 1.22.4 to 1.23.2

@amusasrd
Copy link

amusasrd commented Oct 27, 2024

Wow I spent so long trying to fix this, only for it to be a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants