Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
406 stars 196 forks source link

[Issue] app crash when container app language is not specified #2935

Open sinedied opened 11 months ago

sinedied commented 11 months ago

Output from azd version Run azd version and copy and paste the output here: azd version 1.4.3 (commit d165bd2de96dae75de57604c0d8a5553ae214618)

Describe the bug When deploying a container app, azd provision or azd up crashes if the language property is not set. This property should be irrelevant in the case of building a Docker image.

Crash log:

azd provision

Provisioning Azure resources (azd provision)
Provisioning Azure resources can take some time.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x40 pc=0x1014b792c]

goroutine 1 [running]:
github.com/azure/azure-dev/cli/azd/pkg/project.(*projectManager).Initialize(0x140004f6ab0, {0x101bb1248, 0x140003ca990}, 0x101baac88?)
        /Users/runner/work/1/s/cli/azd/pkg/project/project_manager.go:81 +0x2c
github.com/azure/azure-dev/cli/azd/cmd.(*provisionAction).Run(0x140004f1000, {0x101bb1248, 0x140003ca990})
        /Users/runner/work/1/s/cli/azd/cmd/provision.go:140 +0x1e8
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x101bb1248?, 0x140003ca990?})
        /Users/runner/work/1/s/cli/azd/cmd/middleware/middleware.go:127 +0x258
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*HooksMiddleware).Run(0x140004ffd00, {0x101bb1248?, 0x140003ca870?}, 0x140004ffa40)
        /Users/runner/work/1/s/cli/azd/cmd/middleware/hooks.go:63 +0xec
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x101bb1248, 0x140003ca870})
        /Users/runner/work/1/s/cli/azd/cmd/middleware/middleware.go:125 +0x20c
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*TelemetryMiddleware).Run(0x140004144e8, {0x101bb1248, 0x1400041fc50}, 0x140004ffa40)
        /Users/runner/work/1/s/cli/azd/cmd/middleware/telemetry.go:75 +0x5c0
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x101bb1248, 0x1400041fc50})
        /Users/runner/work/1/s/cli/azd/cmd/middleware/middleware.go:125 +0x20c
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*ExperimentationMiddleware).Run(0x10172e401?, {0x101bb1248, 0x1400041fc50}, 0x140004ffa40)
        /Users/runner/work/1/s/cli/azd/cmd/middleware/experimentation.go:64 +0x338
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x101bb1248, 0x1400041fc50})
        /Users/runner/work/1/s/cli/azd/cmd/middleware/middleware.go:125 +0x20c
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*DebugMiddleware).Run(0x140004f6b70, {0x101bb1248, 0x1400041fc50}, 0x140004ffa40)
        /Users/runner/work/1/s/cli/azd/cmd/middleware/debug.go:48 +0x30c
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction.func1({0x101bb1248, 0x1400041fc50})
        /Users/runner/work/1/s/cli/azd/cmd/middleware/middleware.go:125 +0x20c
github.com/azure/azure-dev/cli/azd/cmd/middleware.(*MiddlewareRunner).RunAction(0x14000484300, {0x101bb1248, 0x1400041fc50}, 0x101944ee0?, {0x101ba6298?, 0x140004f1000})
        /Users/runner/work/1/s/cli/azd/cmd/middleware/middleware.go:131 +0x1e4
github.com/azure/azure-dev/cli/azd/cmd.(*CobraBuilder).configureActionResolver.func1(0x140003f8f00, {0x10223b780?, 0x0, 0x0})
        /Users/runner/work/1/s/cli/azd/cmd/cobra_builder.go:143 +0x3c0
github.com/spf13/cobra.(*Command).execute(0x140003f8f00, {0x10223b780, 0x0, 0x0})
        /Users/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:856 +0x554
github.com/spf13/cobra.(*Command).ExecuteC(0x140003a7b80)
        /Users/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:974 +0x318
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:902
github.com/spf13/cobra.(*Command).ExecuteContext(0x1018b2400?, {0x101bb1210?, 0x10223b780?})
        /Users/runner/go/pkg/mod/github.com/spf13/cobra@v1.3.0/command.go:895 +0x48
main.main()
        /Users/runner/work/1/s/cli/azd/main.go:61 +0x1b4

To Reproduce Relevant extract from azure.yaml

  backend:
    project: ./src/backend
    language: ts # if this line is omitted, azd crashes
    host: containerapp

Expected behavior Language should be optional for containers, and azd should not crash.

Environment MacOS 14.0

savannahostrowski commented 11 months ago

This is similar to #1645. We don't currently handle a language:none scenario (we probably should though...as the language doesn't matter for ACA hosted apps).

That said, at the very least/in the meantime, we should have better error handling here.

weikanglim commented 11 months ago

IIRC, we used to have a better error message for this since #2066 (language property must be set) but since our internal implementation push to make every component an application lifetime registration, we've somewhat lost visibility into how these conditions should be handled due to the complexity introduced with dependency injection. Not to say that it can't be fixed easily even in our current DI model, but it is certainly harder to spot.

A nil error panic is certainly something we should avoid completely.