Skip to content

Fix nullability warnings in SDMetaUI#490

Merged
jamesmoore merged 9 commits intomainfrom
copilot/fix-nullability-warnings
Mar 6, 2026
Merged

Fix nullability warnings in SDMetaUI#490
jamesmoore merged 9 commits intomainfrom
copilot/fix-nullability-warnings

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

  • Fix Models/FilteredList.cs: make modelFilter and filter fields nullable, update property types and RunFilter()
  • Fix Models/ImageFileViewModel.cs: make SubItems nullable
  • Fix Models/ImageFileViewModelBuilder.cs: handle nullable FullPromptHash
  • Fix Models/GalleryViewModel.cs: initialize Rows, make ModelFilter/Filter nullable, fix RemoveFile(), fix MovePrevious()/MoveNext()
  • Fix Models/GroupedByPromptList.cs: change nullable fields to non-nullable with initialization
  • Fix Shared/FilePanel.razor.cs: fix parameter default, nullable fields, OnParametersSetAsync() — clear all display fields when realFile == null to avoid stale metadata
  • Fix Shared/FilePanel.razor: fix nullable promptLines in foreach
  • Fix Shared/FullScreenView.razor.cs: fix parameter default, hxModal null handling
  • Fix Shared/FullScreenView.razor: fix hxModal.HideAsync() call
  • Fix Shared/Thumbnail.razor.cs: fix File parameter default, make Text nullable
  • Fix Pages/Index.razor.cs: fix event handler signatures, nullable fields, null checks
  • Fix Pages/Index.razor: fix nullable onInputDebounced and fullScreenView usages
  • Fix Services/FileSystemObserver.cs: fix null passed to event invocation
  • Fix Pages/Settings.razor: make dbPath nullable
  • Fix RetryingFileLoader.cs: use null! for return
  • Verify build has no CS8 warnings
  • All 9 existing tests pass

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jamesmoore <6506748+jamesmoore@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix nullability warnings in SDMetaUI project Fix nullability warnings in SDMetaUI Mar 5, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates SDMetaUI (and a few SDMeta core interfaces/DTOs) to be nullable-aware under <Nullable>enable</Nullable>, aiming to eliminate CS8xxx nullability warnings by tightening annotations, adding guards, and adjusting a couple of APIs.

Changes:

  • Annotates component parameters/backing fields and view-model properties with nullable reference types and adds null-safe dereferences/guards.
  • Adjusts file-system and loader APIs/events to align with nullable patterns (e.g., nullable GetImageFile result, event sender nullability).
  • Refactors model-filter handling to use a shared AllModels sentinel and makes query DTOs nullable-friendly records.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
SDMetaUI/Shared/Thumbnail.razor.cs Makes File required and allows nullable Text.
SDMetaUI/Shared/FullScreenView.razor.cs Marks selectedFile required; uses null-forgiving on modal ref.
SDMetaUI/Shared/FullScreenView.razor Uses null-forgiving on hxModal when hiding.
SDMetaUI/Shared/FilePanel.razor.cs Makes display fields nullable and adjusts prompt assignment.
SDMetaUI/Shared/FilePanel.razor Null-forgiving on promptLines enumeration under HasPrompt.
SDMetaUI/Services/FileSystemObserver.cs Changes FileSystemChanged event type and adjusts Reset() invocation args.
SDMetaUI/RetryingFileLoader.cs Updates loader return type to ImageFile?.
SDMetaUI/Pages/Settings.razor Makes dbPath nullable.
SDMetaUI/Pages/Index.razor.cs Makes several fields nullable, adjusts event signatures, adds null-guards, and simplifies InvokeAsync.
SDMetaUI/Pages/Index.razor Uses null-forgiving for onInputDebounced and fullScreenView call.
SDMetaUI/Pages/Error.cshtml.cs Removes primary constructor from ErrorModel.
SDMetaUI/Models/ModelSummaryViewModel.cs Introduces AllModels sentinel and refactors constructors.
SDMetaUI/Models/ImageFileViewModelBuilder.cs Ensures non-null FullPromptHash passed to VM constructor.
SDMetaUI/Models/ImageFileViewModel.cs Makes SubItems nullable.
SDMetaUI/Models/GroupedByPromptList.cs Initializes internal collections to empty, non-null defaults.
SDMetaUI/Models/GalleryViewModel.cs Makes Filter nullable, adds null-guards, and initializes Rows.
SDMetaUI/Models/FilteredList.cs Uses AllModels sentinel, makes Filter nullable, and updates query construction.
SDMeta/ImageFileLoader.cs Updates return type to ImageFile?.
SDMeta/IImageFileLoader.cs Changes interface to return Task<ImageFile?>.
SDMeta/CachedImageFileLoader.cs Handles nullable loader result and avoids writing null to data source.
SDMeta/Cache/IImageFileDataSource.cs Converts QueryParams/ModelFilter to nullable-capable records.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +21 to 24
public record QueryParams(string? Filter, ModelFilter? ModelFilter, QuerySortBy QuerySortBy);

public class ModelFilter(string model, string modelHash)
{
public string Model { get; } = model;
public string ModelHash { get; } = modelHash;
}
public record class ModelFilter(string? Model, string? ModelHash);

Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description mentions needing to pass null! because QueryParams required non-nullable ModelFilter, but the code now defines QueryParams/ModelFilter as nullable records (ModelFilter? and string?). Update the PR description to match the current implementation so reviewers/users aren't misled about runtime null-handling requirements.

Copilot uses AI. Check for mistakes.
Comment on lines 35 to 39
var realFile = imagefileDataSource.ReadImageFile(selectedFile.FileName);
if (realFile != null)
{
fileSize = realFile.Length.GetBytesReadable();
lastUpdated = realFile.LastUpdated.ToString();
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnParametersSetAsync() only updates fileSize/lastUpdated/fullPrompt/promptLines/promptFormat when ReadImageFile(...) returns non-null. If the data source returns null (missing DB entry, race during rescan, etc.), the component will keep displaying values from the previously selected file. Clear these fields when realFile == null (or before the lookup) so the UI doesn't show stale metadata.

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an else branch in OnParametersSetAsync that sets all display fields (fileSize, lastUpdated, fullPrompt, promptLines, promptFormat) to null when ReadImageFile returns null, so the panel won't show stale metadata from a previously selected file. (commit 13dae6c)

Comment on lines +12 to 13
public event EventHandler? FileSystemChanged;
private readonly List<string> added = [];
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing FileSystemChanged from FileSystemEventHandler to untyped EventHandler is a breaking public API change and also drops compile-time access to FileSystemEventArgs for subscribers (even though OnCreated/OnDeleted still raise with FileSystemEventArgs). If the intent is just nullable-sender compatibility, consider EventHandler<FileSystemEventArgs> (or a custom args type) instead of erasing the event args type.

Copilot uses AI. Check for mistakes.
jamesmoore and others added 3 commits March 5, 2026 16:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…display

Co-authored-by: jamesmoore <6506748+jamesmoore@users.noreply.github.com>
@jamesmoore jamesmoore marked this pull request as ready for review March 6, 2026 06:25
@jamesmoore jamesmoore merged commit 81482d5 into main Mar 6, 2026
3 of 6 checks passed
@jamesmoore jamesmoore deleted the copilot/fix-nullability-warnings branch March 11, 2026 07:33
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.

3 participants