{"record":{"id":"b87f6b7505220fff","repo":"felixse/FluentTerminal","slug":"failed-to-read-the-file","errorCode":null,"errorMessage":"Failed to read the file.","messagePattern":"Failed to read the file\\.","errorType":"exception","errorClass":"ReadTextFileException","httpStatus":null,"severity":"error","filePath":"FluentTerminal.App.Services/Implementation/TrayProcessCommunicationService.cs","lineNumber":93,"sourceCode":"            var response =\n                await GetResponseAsync<CommonResponse>(new SaveTextFileRequest {Path = path, Content = content})\n                    .ConfigureAwait(false);\n\n            if (!response.Success)\n            {\n                throw new SaveTextFileException(string.IsNullOrEmpty(response.Error)\n                    ? \"Failed to save the file.\"\n                    : response.Error);\n            }\n        }\n\n        public async Task<string> ReadTextFileAsync(string path)\n        {\n            var response = await GetResponseAsync<StringValueResponse>(new ReadTextFileRequest { Path = path }).ConfigureAwait(false);\n\n            if (!response.Success)\n            {\n                throw new ReadTextFileException(string.IsNullOrWhiteSpace(response.Error) ? \"Failed to read the file.\" : response.Error);\n            }\n\n            return response.Value;\n        }\n\n        public async Task<string> GetSshConfigDirAsync()\n        {\n            if (!string.IsNullOrEmpty(_sshConfigDir))\n            {\n                return _sshConfigDir;\n            }\n\n            var response =\n                await GetResponseAsync<GetSshConfigFolderResponse>(new GetSshConfigFolderRequest\n                    { IncludeContent = false }).ConfigureAwait(false);\n\n            if (response.Success)\n            {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/felixse/FluentTerminal/blob/ba83ec485eea8d8ee65825711731300bee2e76ed/FluentTerminal.App.Services/Implementation/TrayProcessCommunicationService.cs#L75-L111","documentation":"Thrown by TrayProcessCommunicationService.ReadTextFileAsync when the tray process returns a StringValueResponse with Success == false and a blank Error. Same IPC delegation pattern as SaveTextFileAsync: the UWP app asks the Win32 tray to read a file and, on opaque failure, reports a generic 'Failed to read the file.' message.","triggerScenarios":"ReadTextFileRequest is sent for a path the tray cannot read: missing file, access-denied, path too long, or unreadable encoding. Success=false with empty Error triggers the fallback string.","commonSituations":"Requested file does not exist; path is outside permitted access; file is locked exclusively by another process; tray process lacks read permission; tray handler swallowed the exception without setting Error.","solutions":["Confirm the file exists and is readable at the given path before requesting it.","Ensure the tray-side ReadTextFile handler populates response.Error with the real exception message.","Verify the tray process is running and has the needed privileges.","Catch ReadTextFileException at the call site and degrade gracefully (e.g. return empty/default)."],"exampleFix":"// before\nthrow new ReadTextFileException(string.IsNullOrWhiteSpace(response.Error) ? \"Failed to read the file.\" : response.Error);\n\n// after (tray side) - propagate the underlying cause\n// catch (Exception ex) { return new StringValueResponse { Success = false, Error = ex.Message }; }","handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException(\"path required\");\nif (!System.IO.File.Exists(path)) throw new System.IO.FileNotFoundException(path);","typeGuard":null,"tryCatchPattern":"try { content = await tray.ReadTextFileAsync(path); }\ncatch (ReadTextFileException ex) { logger.Warn(ex, \"read failed\"); content = null; }","preventionTips":["Check File.Exists and readability before requesting via the tray.","Make the tray handler return the underlying exception in response.Error.","Keep a fallback/default when a read is non-critical.","Verify the tray process is alive."],"tags":["file-io","tray-ipc","appservice","permissions","uwp"],"backgroundTag":null,"analyzedSha":"ba83ec485eea8d8ee65825711731300bee2e76ed","analyzedAt":"2026-08-13T21:23:15.467Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}