Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.32k stars 433 forks source link

When local.settings.json is absent, runnig `func host start` does not work for newer worker models #3544

Closed kshyju closed 5 days ago

kshyju commented 11 months ago

With worker indexing enabled, when local.settings.json is absent, runnnig func host start does not work. The terminal becomes stuck.

See https://github.com/Azure/azure-functions-dotnet-worker/issues/2107#issuecomment-1836736389

mattchenderson commented 10 months ago

To address this, the Core Tools should emit a warning if FUNCTIONS_WORKER_RUNTIME is not provided (either as an environment variable or in the local.settings.json as it processes that). This should occur prior to the WebHost even being built. The warning should indicate that this value is not present and should be set in local.settings.json.

That would satisfy the minimum scope. However, we should consider going further. The Core Tools can assist with putting the setting into local.settings.json. One option is to prompt the user and persist the result as part of this overall compensating action. However, it may be sufficient to simply provide the func settings add command with a list of acceptable values (as in the func init experience).

mattchenderson commented 10 months ago

Edited title to reflect that this problem is broader than just with worker indexing, though it will always apply when worker indexing is required.

sinedied commented 7 months ago

When using JavaScript/TypeScript v4 runtime, the host does not find any functions at all when local.settings.json is missing. It also reports an unclear warning (related: https://github.com/Azure/azure-functions-core-tools/issues/3560) which does not help solving the issue.

Since local.settings.json is excluded from git by default but needed to run the newer runtime, what about creating it automatically when none is found?

VineethReyya commented 1 month ago

Hi @fabiocav, could you provide more overview to replicate the issue?

sinedied commented 1 month ago

@VineethReyya just initialize a new functions projects using the VS Code extension (for example) and choose JS/TS with v4 runtime. Then delete local.settings.json, and try to run the functions with func start

VineethReyya commented 1 month ago

@VineethReyya just initialize a new functions projects using the VS Code extension (for example) and choose JS/TS with v4 runtime. Then delete local.settings.json, and try to run the functions with func start

Hi @sinedied Thanks for the help. I am able to replicate the scenario showing errors message when local.settings.json is missing. Could you help me out with more overview on what exactly the issue with showing error message, so that we can come up with a workaround for this.

sinedied commented 1 month ago

For traceability, this is the error message you get when the local.settings.json file is missing:

func start
Can't determine project language from files. Please use one of [--dotnet-isolated, --dotnet, --javascript, --typescript, --java, --python, --powershell, --custom]
Can't determine project language from files. Please use one of [--dotnet-isolated, --dotnet, --javascript, --typescript, --java, --python, --powershell, --custom]
Can't determine project language from files. Please use one of [--dotnet-isolated, --dotnet, --javascript, --typescript, --java, --python, --powershell, --custom]

Azure Functions Core Tools
Core Tools Version:       4.0.5858 Commit hash: N/A +f9ca1cc1f385317a558bc35b3a3fc96af22665e4 (64-bit)
Function Runtime Version: 4.834.3.22875

Can't determine project language from files. Please use one of [--dotnet-isolated, --dotnet, --javascript, --typescript, --java, --python, --powershell, --custom]
Can't determine project language from files. Please use one of [--dotnet-isolated, --dotnet, --javascript, --typescript, --java, --python, --powershell, --custom]
Can't determine project language from files. Please use one of [--dotnet-isolated, --dotnet, --javascript, --typescript, --java, --python, --powershell, --custom]
[2024-09-20T07:17:57.122Z] The 'FUNCTIONS_WORKER_RUNTIME' setting is required. Please specify a valid value. See https://go.microsoft.com/fwlink/?linkid=2257963 for more information. The application will continue to run, but may throw an exception in a future release.
[2024-09-20T07:17:57.175Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
For detailed output, run func with --verbose flag.
[2024-09-20T07:18:02.119Z] Host lock lease acquired by instance ID '0000000000000000000000008E3F1154'.

There should be enough context though to automatically determine which runtime to use:

Moreover, even when specifying the language with func start --javascript, you get this error:

func start --javascript

Azure Functions Core Tools
Core Tools Version:       4.0.5858 Commit hash: N/A +f9ca1cc1f385317a558bc35b3a3fc96af22665e4 (64-bit)
Function Runtime Version: 4.834.3.22875

[2024-09-20T07:22:45.538Z] The 'FUNCTIONS_WORKER_RUNTIME' setting is required. Please specify a valid value. See https://go.microsoft.com/fwlink/?linkid=2257963 for more information. The application will continue to run, but may throw an exception in a future release.
[2024-09-20T07:22:45.589Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
For detailed output, run func with --verbose flag.
[2024-09-20T07:22:50.538Z] Host lock lease acquired by instance ID '0000000000000000000000008E3F1154'.

As explained above, detecting which runtime to use should be trivial, looking for the @azure/functions dependency.