{"record":{"id":"24755a2309d36e05","repo":"Uahh/ToastFish","slug":"ex-message","errorCode":null,"errorMessage":"ex.Message","messagePattern":"ex\\.Message","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"Model/Mp3/PlayMp3.cs","lineNumber":177,"sourceCode":"                // FileStream fs = new FileStream(path, FileMode.Open);\n                //fs.Seek(-128, SeekOrigin.End);\n                fs.Read(b, 0, 16);\n                //Set flag\n                String sFlag = System.Text.Encoding.Default.GetString(b, 0, 4).ToUpper();\n                String sType = System.Text.Encoding.Default.GetString(b, 8, 4).ToUpper();\n                if (sFlag.CompareTo(\"RIFF\") == 0) isSet1 = true;\n                if (sType.CompareTo(\"WAVE\") == 0) isSet2 = true;\n\n                if (isSet1 && isSet2)\n                {\n                    isWave = true;\n                }\n                fs.Close();\n                fs.Dispose();\n            }\n            catch (IOException ex)\n            {\n                System.Windows.MessageBox.Show(ex.Message);\n            }\n\n            return isWave;\n        }\n    }\n    public class APIClass\n    {\n        [DllImport(\"kernel32.dll\", CharSet = CharSet.Auto)]\n        public static extern int GetShortPathName(\n         string lpszLongPath,\n         string shortFile,\n         int cchBuffer\n      );\n        [DllImport(\"winmm.dll\", EntryPoint = \"mciSendString\", CharSet = CharSet.Auto)]\n        public static extern int mciSendString(\n           string lpstrCommand,\n           string lpstrReturnString,\n           int uReturnLength,","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/Uahh/ToastFish/blob/2508784a6650862a60e1f3ec3a54dd83efdec98b/Model/Mp3/PlayMp3.cs#L159-L195","documentation":"isFileWave validates whether a file is a WAV file by reading its header through a FileStream; an IOException (file locked, device error, disk full, network path failure) during that read is caught and shown as a raw message box. It is a low-level I/O failure, not a format problem — a non-WAV file simply returns isWave=false without any exception.","triggerScenarios":"PlayMp3/isFileWave is called on an mp3/wav path while another process (player, antivirus, indexer) holds the file open exclusively, the file is on an unavailable network/USB drive, or the stream read hits a disk error mid-header-read.","commonSituations":"Audio file still being written by a download when playback is attempted; removable media unplugged mid-scan; Windows file locking after a crashed player; long-path or permission issues surfacing as IOException.","solutions":["Retry after closing applications that may hold the file open (media players, editors)","Check the file exists and is on an available local disk before calling","Release/Dispose any FileStream you opened previously on the same path before probing it","Catch IOException explicitly in caller code and fall back to SpeechSynthesizer playback instead of failing"],"exampleFix":"// before\ntry { isWave = CheckWaveHeader(fs); }\ncatch (IOException ex) { MessageBox.Show(ex.Message); }\n// after\ntry { isWave = CheckWaveHeader(fs); }\ncatch (IOException ex)\n{\n    Debug.WriteLine($\"WAV probe failed for {path}: {ex.Message}\");\n    isWave = false; // caller falls back to TTS\n}","handlingStrategy":"try-catch","validationCode":"if (!File.Exists(path)) return false;\ntry { using File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read); return true; }\ncatch (IOException) { return false; }","typeGuard":"null","tryCatchPattern":"try { isWave = isFileWave(path); }\ncatch (IOException ex) { Debug.WriteLine($\"WAV probe IO error: {ex.Message}\"); isWave = false; }\ncatch (Exception ex) { Debug.WriteLine(ex.Message); isWave = false; }","preventionTips":["Close all FileStreams on the file before probing it","Retry once after a short delay if the file may still be downloading","Copy network/removable-media files to a local temp path first","Fall back to TTS (SpeechSynthesizer) instead of failing the playback"],"tags":["csharp","io","audio","file-lock","wav"],"backgroundTag":"file-read-failed","analyzedSha":"2508784a6650862a60e1f3ec3a54dd83efdec98b","analyzedAt":"2026-09-15T23:21:32.897Z","contentChangedAt":"2026-09-15T23:21:32.897Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}