Skip to content

Commit

Permalink
Fix unexpected nil dereference when it runs lambroll init for not-e…
Browse files Browse the repository at this point in the history
…xisted function

Previously it raises the error like the following:

```
$ lambroll init --function-name __NOT_EXISTS_FUNC__
2021/12/21 14:27:11 [info] lambroll v0.12.6
2021/12/21 14:27:12 [info] function __NOT_EXISTS_FUNC__ is not found
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x190c412]

goroutine 1 [running]:
github.com/fujiwara/lambroll.newFunctionFrom(0xc00099f7c0, 0x0, 0x0)
        /home/runner/work/lambroll/lambroll/lambroll.go:248 +0x432
github.com/fujiwara/lambroll.(*App).Init(0xc0000c0280, {0xc0003f6750, 0xc0004a0601})
        /home/runner/work/lambroll/lambroll/init.go:73 +0x4f5
main._main()
        /home/runner/work/lambroll/lambroll/cmd/lambroll/main.go:142 +0x4e0f
main.main()
        /home/runner/work/lambroll/lambroll/cmd/lambroll/main.go:19 +0x19
```

This patch fixes that unexpected nil dereference:

```
$ lambroll init --function-name __NOT_EXISTS_FUNC__
2021/12/21 14:59:19 [info] lambroll v0.12.0-28-g73ebdbe
2021/12/21 14:59:20 [info] function __NOT_EXISTS_FUNC__ is not found
2021/12/21 14:59:20 [info] creating .lambdaignore
2021/12/21 14:59:20 [info] creating function.json
2021/12/21 14:59:20 [info] completed
```

Signed-off-by: moznion <moznion@mail.moznion.net>
  • Loading branch information
moznion committed Dec 21, 2021
1 parent 73ebdbe commit 2f8b5c6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lambroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func newFunctionFrom(c *lambda.FunctionConfiguration, code *lambda.FunctionCodeL
}
}

if aws.StringValue(code.RepositoryType) == "ECR" || aws.StringValue(fn.PackageType) == packageTypeImage {
if (code != nil && aws.StringValue(code.RepositoryType) == "ECR") || aws.StringValue(fn.PackageType) == packageTypeImage {
log.Printf("[debug] Image URL=%s", *code.ImageUri)
fn.PackageType = aws.String(packageTypeImage)
fn.Code = &lambda.FunctionCode{
Expand Down

0 comments on commit 2f8b5c6

Please sign in to comment.