From d1a0fd23ec8aa601fb5d32d4089d629199843256 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Mon, 8 Dec 2025 21:05:01 +0100 Subject: [PATCH] Added logging for file loading process and error handling --- .../Components/ReadFileContent.razor.cs | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/app/MindWork AI Studio/Components/ReadFileContent.razor.cs b/app/MindWork AI Studio/Components/ReadFileContent.razor.cs index 4c636567..d09bea4b 100644 --- a/app/MindWork AI Studio/Components/ReadFileContent.razor.cs +++ b/app/MindWork AI Studio/Components/ReadFileContent.razor.cs @@ -29,31 +29,49 @@ public partial class ReadFileContent : MSGComponentBase { var selectedFile = await this.RustService.SelectFile(T("Select file to read its content")); if (selectedFile.UserCancelled) + { + this.Logger.LogInformation("User cancelled the file selection"); return; - + } + if(!File.Exists(selectedFile.SelectedFilePath)) + { + this.Logger.LogWarning("Selected file does not exist: '{FilePath}'", selectedFile.SelectedFilePath); return; - + } + var ext = Path.GetExtension(selectedFile.SelectedFilePath).TrimStart('.'); if (Array.Exists(FileTypeFilter.Executables.FilterExtensions, x => x.Equals(ext, StringComparison.OrdinalIgnoreCase))) { + this.Logger.LogWarning("User attempted to load executable file: {FilePath} with extension: {Extension}", selectedFile.SelectedFilePath, ext); await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.AppBlocking, T("Executables are not allowed"))); return; } - + if (Array.Exists(FileTypeFilter.AllImages.FilterExtensions, x => x.Equals(ext, StringComparison.OrdinalIgnoreCase))) { + this.Logger.LogWarning("User attempted to load image file: {FilePath} with extension: {Extension}", selectedFile.SelectedFilePath, ext); await MessageBus.INSTANCE.SendWarning(new(Icons.Material.Filled.ImageNotSupported, T("Images are not supported yet"))); return; } - + if (Array.Exists(FileTypeFilter.AllVideos.FilterExtensions, x => x.Equals(ext, StringComparison.OrdinalIgnoreCase))) { + this.Logger.LogWarning("User attempted to load video file: {FilePath} with extension: {Extension}", selectedFile.SelectedFilePath, ext); await MessageBus.INSTANCE.SendWarning(new(Icons.Material.Filled.FeaturedVideo, this.T("Videos are not supported yet"))); return; } - - var fileContent = await UserFile.LoadFileData(selectedFile.SelectedFilePath, this.RustService, this.DialogService); - await this.FileContentChanged.InvokeAsync(fileContent); + + try + { + var fileContent = await UserFile.LoadFileData(selectedFile.SelectedFilePath, this.RustService, this.DialogService); + await this.FileContentChanged.InvokeAsync(fileContent); + this.Logger.LogInformation("Successfully loaded file content: {FilePath}", selectedFile.SelectedFilePath); + } + catch (Exception ex) + { + this.Logger.LogError(ex, "Failed to load file content: {FilePath}", selectedFile.SelectedFilePath); + await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.Error, T("Failed to load file content"))); + } } } \ No newline at end of file