Skip to content

fix: Use specific exception types in ArmClientExtensions#1689

Merged
thomhurst merged 1 commit into
mainfrom
fix/error-handling
Dec 30, 2025
Merged

fix: Use specific exception types in ArmClientExtensions#1689
thomhurst merged 1 commit into
mainfrom
fix/error-handling

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Summary

  • Creates AzureResourceNotFoundException (inherits InvalidOperationException) for when resources cannot be found
  • Creates UnsupportedAzureScopeException (inherits NotSupportedException) for unsupported scope types
  • Replaces generic throw new Exception(...) with these specific exceptions
  • Adds XML documentation explaining when each exception is thrown

Note: Issue #1574 (SuccessHttpHandler) was already fixed in a previous commit that removed the class entirely.

Fixes #1578

Test plan

  • Build passes

🤖 Generated with Claude Code

Replace generic Exception throws with specific, descriptive exceptions:

- AzureResourceNotFoundException: Thrown when a resource cannot be found
  in the resource group. Inherits from InvalidOperationException and
  includes the ResourceIdentifier for debugging.

- UnsupportedAzureScopeException: Thrown when an unsupported scope type
  is encountered. Inherits from NotSupportedException and includes the
  Scope object for debugging.

Added XML documentation for GetResourceIdentifierAsync explaining when
each exception is thrown.

Note: Issue #1574 (SuccessHttpHandler) was already fixed in commit
828c5b5 which removed the SuccessHttpHandler class entirely.

Fixes #1578

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@thomhurst

Copy link
Copy Markdown
Owner Author

Summary

Replaces generic exceptions with custom typed exceptions for Azure resource operations.

Critical Issues

None found ✅

Suggestions

Exception Constructor Consistency

Both new exception classes follow good practices with proper constructors accepting innerException. However, consider if serialization support is needed (though unlikely for ModularPipelines use case).

Error Message Quality

In UnsupportedAzureScopeException:20, the error message includes both the type name AND the scope value. Since AzureScope is a record, the ToString() output might be redundant with the type name. Consider if this provides useful information or just noise.

Example output would be:
Unsupported Azure scope type: AzureManagementGroupIdentifier.
Scope value: AzureManagementGroupIdentifier { Name = "test" }

If the scope value is useful for debugging, this is fine. If not, you could simplify to just the type name.

XML Documentation Completeness

The XML documentation is well-written. The exceptions are properly marked with tags in the extension method's XML doc, which is excellent for API consumers.

Previous Review Status

Cannot access previous comments due to GitHub token scope limitations.

Verdict

✅ APPROVE - No critical issues

The PR improves exception handling by replacing generic exceptions with strongly-typed, semantically meaningful exceptions. This makes it easier for consumers to catch and handle specific error scenarios. The implementation follows standard exception patterns with proper inheritance (InvalidOperationException for "not found", NotSupportedException for "unsupported scope") and includes well-documented constructors.

@thomhurst thomhurst merged commit 10d1fad into main Dec 30, 2025
12 checks passed
@thomhurst thomhurst deleted the fix/error-handling branch December 30, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code smell: Azure ArmClientExtensions.GetResourceIdentifierAsync throws generic Exception

1 participant