{"record":{"id":"26ddd371dea31212","repo":"plandex-ai/plandex","slug":"error-unmarshalling-azure-deployments-map-w","errorCode":null,"errorMessage":"error unmarshalling AZURE_DEPLOYMENTS_MAP: %w","messagePattern":"error unmarshalling AZURE_DEPLOYMENTS_MAP: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/model/client.go","lineNumber":259,"sourceCode":"\t\tif authVars[\"VERTEXAI_LOCATION\"] != \"\" {\n\t\t\textendedReq.VertexLocation = authVars[\"VERTEXAI_LOCATION\"]\n\t\t}\n\t\tif authVars[\"GOOGLE_APPLICATION_CREDENTIALS\"] != \"\" {\n\t\t\textendedReq.VertexCredentials = authVars[\"GOOGLE_APPLICATION_CREDENTIALS\"]\n\t\t}\n\tcase shared.ModelProviderAzureOpenAI:\n\t\tif authVars[\"AZURE_API_BASE\"] != \"\" {\n\t\t\textendedReq.LiteLLMApiBase = authVars[\"AZURE_API_BASE\"]\n\t\t}\n\t\tif authVars[\"AZURE_API_VERSION\"] != \"\" {\n\t\t\textendedReq.AzureApiVersion = authVars[\"AZURE_API_VERSION\"]\n\t\t}\n\n\t\tif authVars[\"AZURE_DEPLOYMENTS_MAP\"] != \"\" {\n\t\t\tvar azureDeploymentsMap map[string]string\n\t\t\terr := json.Unmarshal([]byte(authVars[\"AZURE_DEPLOYMENTS_MAP\"]), &azureDeploymentsMap)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error unmarshalling AZURE_DEPLOYMENTS_MAP: %w\", err)\n\t\t\t}\n\t\t\tmodelName := string(extendedReq.Model)\n\t\t\tmodelName = strings.ReplaceAll(modelName, \"azure/\", \"\")\n\n\t\t\tdeploymentName, ok := azureDeploymentsMap[modelName]\n\t\t\tif ok {\n\t\t\t\tlog.Println(\"azure - deploymentName\", deploymentName)\n\t\t\t\tmodelName = \"azure/\" + deploymentName\n\t\t\t\textendedReq.Model = shared.ModelName(modelName)\n\t\t\t}\n\t\t}\n\n\t\t// azure uses 'reasoning_config' instead of 'reasoning' like direct openai api\n\t\tif extendedReq.ReasoningConfig != nil {\n\t\t\textendedReq.AzureReasoningEffort = extendedReq.ReasoningConfig.Effort\n\t\t\textendedReq.ReasoningConfig = nil\n\t\t}\n\tcase shared.ModelProviderAmazonBedrock:","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/model/client.go#L241-L277","documentation":"For Azure OpenAI deployments the library reads the AZURE_DEPLOYMENTS_MAP auth var, expected to be a JSON object mapping model names to Azure deployment names, and unmarshals it with json.Unmarshal. If the env var holds invalid JSON, the request fails with \"error unmarshalling AZURE_DEPLOYMENTS_MAP: %w\" wrapping the json error.","triggerScenarios":"createChatCompletionStreamExtended runs with baseModelConfig.Provider == AzureOpenAI and authVars[\"AZURE_DEPLOYMENTS_MAP\"] is non-empty but not valid JSON (e.g. single-quoted keys, trailing comma, YAML, or shell-mangled quoting) so json.Unmarshal into map[string]string fails.","commonSituations":"Setting AZURE_DEPLOYMENTS_MAP='{\"gpt-4o\": \"gpt-4o-deploy\"}' with single quotes eaten by the shell; pasting a YAML-style mapping; values containing characters that break map[string]string (non-string values); shell escaping stripping inner double quotes in docker/compose env files.","solutions":["Validate the env var with jq before use: echo \"$AZURE_DEPLOYMENTS_MAP\" | jq -e 'type == \"object\"' — fix the JSON until it passes.","Ensure the value is a JSON object of string-to-string, using double quotes inside, e.g. {\"gpt-4o\":\"my-deployment\"}.","In docker-compose/K8s, quote the value so inner double quotes survive; prefer a JSON env file over inline shell.","Optionally parse at startup (not per-request) so misconfiguration fails immediately with a clear message."],"exampleFix":"// before\nAZURE_DEPLOYMENTS_MAP = {'gpt-4o': 'gpt-4o-deploy'}   // invalid JSON -> unmarshal error\n// after\nAZURE_DEPLOYMENTS_MAP = '{\"gpt-4o\": \"gpt-4o-deploy\"}'  // valid JSON object","handlingStrategy":"validation","validationCode":"// validate before starting/sending requests\nval := os.Getenv(\"AZURE_DEPLOYMENTS_MAP\")\nif val != \"\" {\n    var m map[string]string\n    if err := json.Unmarshal([]byte(val), &m); err != nil {\n        panic(fmt.Sprintf(\"AZURE_DEPLOYMENTS_MAP is not valid JSON: %v\", err))\n    }\n}","typeGuard":"func isValidDeploymentsMap(s string) bool {\n    if s == \"\" {\n        return true\n    }\n    var m map[string]string\n    return json.Unmarshal([]byte(s), &m) == nil\n}","tryCatchPattern":"resp, err := client.CreateChatCompletionStream(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"AZURE_DEPLOYMENTS_MAP\") {\n    return fmt.Errorf(\"fix AZURE_DEPLOYMENTS_MAP: must be a JSON object like {\\\"gpt-4o\\\":\\\"my-deploy\\\"}: %w\", err)\n}","preventionTips":["Store the map as strict JSON with double-quoted keys/values; test with jq before deploying.","In shell/docker, single-quote the whole value so inner double quotes survive.","Parse the env var once at startup instead of per request to surface errors immediately.","Add a CI check that lints required env vars as JSON."],"tags":["go","json","azure","env-var","configuration"],"backgroundTag":"invalid-json-env-var","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}