Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changes:
- section: "Bugs Fixed"
description: "Fixed `azureterraform_azapi_get` returning `500 InternalServerError` for invalid resource type or API version inputs. The tool now returns `400 BadRequest` with an actionable message, enabling agents to auto-correct and retry with valid inputs."
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.IO;
using System.Net;
using Azure.Mcp.Tools.AzureTerraform.Models;
using Azure.Mcp.Tools.AzureTerraform.Options;
Expand Down Expand Up @@ -55,6 +56,12 @@ protected override AzApiDocsOptions BindOptions(ParseResult parseResult)
};
}

protected override HttpStatusCode GetStatusCode(Exception ex) => ex switch
{
InvalidDataException => HttpStatusCode.BadRequest,
_ => base.GetStatusCode(ex)
};

public override async Task<CommandResponse> ExecuteAsync(
CommandContext context,
ParseResult parseResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public async Task ExecuteAsync_ServiceThrows_HandlesException()

var response = await ExecuteCommandAsync("--resource-type", "Microsoft.Fake/nonexistent");

Assert.NotEqual(HttpStatusCode.OK, response.Status);
Assert.Equal(HttpStatusCode.BadRequest, response.Status);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ public string[] GetResourceApiVersions(string resourceTypeName)
{
(string providerName, _, _) = ResourceParser.ParseResourceType(resourceTypeName);

if (!GetAllResourceTypesAndVersionsByProvider().TryGetValue(providerName, out ProviderResourceTypes? provider))
if (!GetAllResourceTypesAndVersionsByProvider().TryGetValue(providerName, out ProviderResourceTypes? provider)
|| !provider.ResourceTypes.TryGetValue(resourceTypeName.ToLowerInvariant(), out UniqueResourceType? uniqueResourceType))
Comment thread
vcolin7 marked this conversation as resolved.
{
throw new Exception($"Resource type {resourceTypeName} not found.");
throw new InvalidDataException($"Resource type {resourceTypeName} not found.");
Comment thread
vcolin7 marked this conversation as resolved.
}

return [.. provider.ResourceTypes[resourceTypeName.ToLowerInvariant()].ApiVersions];
return [.. uniqueResourceType.ApiVersions];
}

public TypesDefinitionResult LoadSingleResource(string resourceTypeName, string apiVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void GetResourcePropertySchema_ShouldThrowOnNotFound()
SchemaGenerator.ConfigureServices(serviceCollection);
IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

var exception = Assert.Throws<Exception>(() =>
var exception = Assert.Throws<InvalidDataException>(() =>
{
TypesDefinitionResult result = SchemaGenerator.GetResourceTypeDefinitions(serviceProvider, "Microsoft.Unknown/virtualRandom");
_ = SchemaGenerator.GetResponse(result);
Expand Down