Skip to content

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

@distinctdan

Description

@distinctdan

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"
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions