Azure / Azure/azure-functions-host
Corrupted secret file D:\home\data\functions\secrets\host.json doesn't lead to meaningful error message
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
I reproed this in v1 and v2, but let's focus on v2. In a clean new app, I removed the ending brace to make the json invalid.
In portail, when running the http function, all I saw is this cryptic response:
```json
{
"id": "2d2d9164-4ec9-4a82-8ed7-a38a07048186",
"requestId": "9f77d6a5-a927-4b7f-aad4-8fe26218718d",
"statusCode": 500,
"errorCode": 0,
"message": "An error has occurred. For more information, please check the logs for error ID 2d2d9164-4ec9-4a82-8ed7-a38a07048186"
}
```
In system logs, here was the full exception:
```
Newtonsoft.Json.JsonReaderException : Unexpected end of content while loading JObject. Path 'source', line 25, position 0.
at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader,JsonLoadSettings options)
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader,JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json,JsonLoadSettings settings)
at Microsoft.Azure.WebJobs.Script.WebHost.ScriptSecretSerializer.ResolveSerializerAndRun[TResult](String secretsJson,Type secretsType,Func`3 func) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\Security\Serialization\ScriptSecretSerializer.cs : 35
at Microsoft.Azure.WebJobs.Script.WebHost.ScriptSecretSerializer.DeserializeSecrets[T](String secretsJson) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\Security\Serialization\ScriptSecretSerializer.cs : 31
at async Microsoft.Azure.WebJobs.Script.WebHost.SecretManager.LoadSecretsAsync(??) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\Security\SecretManager.cs : 371
at async Microsoft.Azure.WebJobs.Script.WebHost.SecretManager.LoadSecretsAsync[T](??) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\Security\SecretManager.cs : 360
at async Microsoft.Azure.WebJobs.Script.WebHost.SecretManager.GetHostSecretsAsync() at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\Security\SecretManager.cs : 72
at async Microsoft.Azure.WebJobs.Script.WebHost.Filters.AuthorizationLevelAttribute.GetAuthorizationResultAsync(??) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\Filters\AuthorizationLevelAttribute.cs : 107
at async Microsoft.Azure.WebJobs.Script.Host.FunctionRequestInvoker.DetermineAuthorizationLevelAsync(HttpRequestMessage request) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\FunctionRequestInvoker.cs : 131
at async Microsoft.Azure.WebJobs.Script.Host.FunctionRequestInvoker.PreprocessRequestAsync(HttpRequestMessage request) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\FunctionRequestInvoker.cs : 108
at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\Controllers\FunctionsController.cs : 39
at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.WebScriptHostHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\Handlers\WebScriptHostHandler.cs : 42
at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.SystemTraceHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-script\src\WebJobs.Script.WebHost\Handlers\SystemTraceHandler.cs : 54
at async System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
```
Let's try to make this a 'self-solve' scenario so it doesn't become a support call.
Contributor guide
Research direction
Reproduce the malformed host.json scenario in v2, then start with ScriptSecretSerializer.cs and follow the secret-loading path through SecretManager.cs and AuthorizationLevelAttribute.cs. The change is done when an invalid secrets file produces a meaningful, actionable error instead of the cryptic generic 500 response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100