Skip to content

Fix type mapping and improve error handling across modules - #14

Merged
antosubash merged 6 commits into
mainfrom
claude/improve-code-quality-MKEBQ
Mar 27, 2026
Merged

antosubash merged 6 commits into
mainfrom
claude/improve-code-quality-MKEBQ

Conversation

@antosubash

@antosubash antosubash commented Mar 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR addresses several issues across the codebase: improves TypeScript type generation for nullable value types and dictionaries, enhances file storage deletion error handling, adds file upload validation, and fixes a React key warning.

Key Changes

TypeScript Type Generation (TypeMappingHelpers.cs)

  • Fixed mapping of nullable value types (e.g., int?) by stripping nested global:: prefixes that Roslyn adds during compilation
  • Added support for mapping Dictionary<K, V>, IDictionary<K, V>, and IReadOnlyDictionary<K, V> to TypeScript Record<K, V> type
  • Added FindTopLevelComma() helper to correctly parse generic type arguments while respecting nested angle brackets
  • Added mapping for object/System.Object to TypeScript unknown type
  • Updated test expectations to reflect correct nullable value type mapping

File Storage Service (FileStorageService.cs)

  • Improved DeleteFileAsync() to handle storage deletion failures gracefully
  • Storage path is now captured before database deletion to ensure it's available for logging if deletion fails
  • Added try-catch block around storage provider deletion with best-effort error handling
  • Added new LogStorageDeletionFailed() logger method to track orphaned storage data

File Upload Endpoint (UploadEndpoint.cs)

  • Added validation to reject requests with missing or empty files
  • Changed IFormFile parameter to nullable and added explicit null/empty check
  • Returns BadRequest with descriptive message for invalid uploads

Chart Component (chart.tsx)

  • Fixed React key warning by using composite key combining parent key and item value instead of item value alone

Notable Implementation Details

  • The FindTopLevelComma() method uses a depth counter to track angle bracket nesting, ensuring correct parsing of complex generic types like Dictionary<List<string>, int>
  • Storage deletion failure is logged but doesn't throw, preventing cascading failures after successful database cleanup
  • File validation happens before stream opening to fail fast on invalid requests

- FileStorage: handle storage deletion failure gracefully in DeleteFileAsync
  to prevent silent orphaned files when storage provider errors
- FileStorage: add null/empty validation for IFormFile in UploadEndpoint
  using TypedResults for consistent return types
- Generator: fix nullable value types (int?) mapping to `any` in TypeScript
  by stripping nested global:: prefixes from Roslyn FQNs
- Generator: add Dictionary/IDictionary/IReadOnlyDictionary support,
  mapping to Record<K, V> in TypeScript instead of `any`
- Generator: map System.Object to `unknown` instead of `any`
- UI: fix chart legend key prop to use composite key for uniqueness
- Add #pragma warning disable CA1031 for the catch-all exception in
  best-effort storage deletion (required for TreatWarningsAsErrors)
- Skip LogFileDeleted when storage deletion fails to avoid misleading
  operators with both "deleted" and "failed" logs for the same file
The Dto_WithDictionary_MapsToRecord test compilation needs an explicit
reference to the assembly containing Dictionary<TKey,TValue>. On some
CI environments, the type-forwarding from System.Runtime.dll may not
resolve correctly, causing the test to fail.
Roslyn's FullyQualifiedFormat with UseSpecialTypes produces "int?" not
"System.Nullable<System.Int32>", so the System.Nullable< check never
matched. Add handling for the T? shorthand form before the explicit
generic form.

Fixes Dto_WithNullableShorthandValueType_MapsToNullUnion test failure
on CI.
@antosubash
antosubash force-pushed the claude/improve-code-quality-MKEBQ branch 2 times, most recently from 8755f81 to 394185b Compare March 27, 2026 21:41
@antosubash
antosubash merged commit 7346d68 into main Mar 27, 2026
2 checks passed
@antosubash
antosubash deleted the claude/improve-code-quality-MKEBQ branch March 27, 2026 21:50
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.

1 participant