Skip to content

fix: Improve HTTP error handling and fix null dereference in code fix provider#1692

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

fix: Improve HTTP error handling and fix null dereference in code fix provider#1692
thomhurst merged 1 commit into
mainfrom
fix/error-handling-round11

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Summary

  • Created HttpResponseException for detailed HTTP error information
  • Added EnsureSuccessStatusCodeWithContentAsync extension method for better error messages
  • Fixed null dereference in AsyncModuleCodeFixProvider

Changes

  • New HttpResponseException.cs: Exception with status code, reason phrase, and response content
  • New HttpResponseExtensions.cs: Extension method for HTTP response validation with content
  • Updated Http.cs and Downloader.cs to use new extension method
  • Fixed AsyncModuleCodeFixProvider.cs: Added null checks using FirstOrDefault()

Fixes #1574, Fixes #1550

Test plan

  • Build succeeds
  • Tests pass

🤖 Generated with Claude Code

Issue #1574 - SuccessHttpHandler unconditionally throws:
- Add HttpResponseException class with detailed error information
- Include status code, reason phrase, response content, and request URI
- Create EnsureSuccessStatusCodeWithContentAsync extension method
- Replace EnsureSuccessStatusCode() calls in Http.cs and Downloader.cs
- Response content is truncated at 2000 chars to avoid excessive messages

Issue #1550 - Null dereference in AsyncModuleCodeFixProvider.AddAsync:
- Replace First()! with FirstOrDefault() for expression syntax lookup
- Add null checks for return statements without expressions
- Add null checks for ArgumentList and inner expression extraction
- Gracefully skip malformed return statements instead of throwing

🤖 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

Improves HTTP error handling with detailed exception messages and adds defensive null checks to the async module code fix provider.

Critical Issues

None found ✅

Suggestions

1. Consider adding tests for the new exception type

The new HttpResponseException class in src/ModularPipelines/Exceptions/HttpResponseException.cs provides valuable error context, but I don't see corresponding tests. Consider adding tests to verify:

  • Exception message formatting with various combinations of status codes, reason phrases, and response content
  • Content truncation behavior when response exceeds 2000 characters
  • Proper handling of null values for optional properties

2. Minor optimization in HttpResponseExtensions.cs:70

The catch block swallows all exceptions when reading response content. While this is acceptable for robustness, consider at least catching specific exceptions like ObjectDisposedException or InvalidOperationException to make the intent clearer. The current approach is safe but slightly less explicit.

3. Code fix analyzer improvements look good

The defensive null checks in AsyncModuleCodeFixProvider.cs are well-implemented:

  • Lines 69-72: Properly handles return statements without expressions
  • Lines 80-87: Safely navigates the syntax tree with null checks
  • The continue statements correctly skip malformed syntax instead of crashing

This addresses potential crashes when the code fix encounters edge cases like bare return; statements or malformed syntax trees.

Verdict

APPROVE - No critical issues

The changes improve error diagnostics significantly by including response content in HTTP exceptions, making debugging much easier. The analyzer fixes add proper null safety for edge cases.

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

Labels

None yet

Projects

None yet

1 participant