cocoa-mhlw / cocoa

Mozilla Public License 2.0
990 stars 113 forks source link

EventLogServiceでDirectoryNotFoundExceptionが起きることがある #1060

Closed keiji closed 2 years ago

keiji commented 2 years ago

その機能リクエストは何らかの問題に関連しますか / Is your feature request related to a problem?

1050 #644 に対応する過程で判明した課題。

送信するイベントログが一件も作られたことがない場合はevent_log_queueディレクトリも作成されない。そのため、送信前にファイルを参照するタイミングでDirectoryNotFoundExceptionが発生する。

送信するログがないのだから、単純にcatchしておけば問題はないが、ログにExceptionとスタックトレースが出ることになるのは、やはり気持ち悪さがある。

"2022/06/25 10:24:59","Info","End","SendAllInternalAsync","/Users/keiji_ariyama/Projects/cocoa/Covid19Radar/Covid19Radar/Services/EventLogService.cs","129","iOS","15.5","iPhone8,4","Physical","APP_VERSION","1.1"
"2022/06/25 10:24:59","Error","Exception, Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '/var/mobile/Containers/Data/Application/B21CE2FC-AC06-4DBE-B62C-8A8DC0529E78/Library/event_log_queue'.  at System.IO.Enumeration.FileSystemEnumerator`1[TResult].CreateDirectoryHandle (System.String path, System.Boolean ignoreNotFound) [0x00032] in <66c50f4174694147beb2fbedff89d188>:0   at System.IO.Enumeration.FileSystemEnumerator`1[TResult]..ctor (System.String directory, System.IO.EnumerationOptions options) [0x00048] in <66c50f4174694147beb2fbedff89d188>:0   at System.IO.Enumeration.FileSystemEnumerable`1+DelegateEnumerator[TResult]..ctor (System.IO.Enumeration.FileSystemEnumerable`1[TResult] enumerable) [0x00000] in <66c50f4174694147beb2fbedff89d188>:0   at System.IO.Enumeration.FileSystemEnumerable`1[TResult]..ctor (System.String directory, System.IO.Enumeration.FileSystemEnumerable`1+FindTransform[TResult] transform, System.IO.EnumerationOptions options) [0x00042] in <66c50f4174694147beb2fbedff89d188>:0   at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles (System.String directory, System.String expression, System.IO.EnumerationOptions options) [0x00014] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs:90   at System.IO.Directory.InternalEnumeratePaths (System.String path, System.String searchPattern, System.IO.SearchTarget searchTarget, System.IO.EnumerationOptions options) [0x0003c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.IO.FileSystem/src/System/IO/Directory.cs:178   at System.IO.Directory.GetFiles (System.String path, System.String searchPattern, System.IO.EnumerationOptions enumerationOptions) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.IO.FileSystem/src/System/IO/Directory.cs:140   at System.IO.Directory.GetFiles (System.String path) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.IO.FileSystem/src/System/IO/Directory.cs:132   at Covid19Radar.Repository.EventLogRepository.GetLogsAsyncInternal (System.Int64 maxSize) [0x0004e] in /Users/keiji_ariyama/Projects/cocoa/Covid19Radar/Covid19Radar/Repository/EventLogRepository.cs:144   at Covid19Radar.Repository.EventLogRepository.GetLogsAsync (System.Int64 maxSize) [0x000c3] in /Users/keiji_ariyama/Projects/cocoa/Covid19Radar/Covid19Radar/Repository/EventLogRepository.cs:125   at Covid19Radar.Services.EventLogService.SendAllInternalAsync (System.Int64 maxSize, System.Int32 maxRetry) [0x00087] in /Users/keiji_ariyama/Projects/cocoa/Covid19Radar/Covid19Radar/Services/EventLogService.cs:71   at Covid19Radar.Services.EventLogService.SendAllAsync (System.Int64 maxSize, System.Int32 maxRetry) [0x000a8] in /Users/keiji_ariyama/Projects/cocoa/Covid19Radar/Covid19Radar/Services/EventLogService.cs:57   at Covid19Radar.iOS.Services.EventLogSubmissionBackgroundService+<>c__DisplayClass5_0.<Schedule>b__1 () [0x0003a] in /Users/keiji_ariyama/Projects/cocoa/Covid19Radar/Covid19Radar.iOS/Services/EventLogSubmissionBackgroundService.cs:52 ","Schedule","/Users/keiji_ariyama/Projects/cocoa/Covid19Radar/Covid19Radar.iOS/Services/EventLogSubmissionBackgroundService.cs","64","iOS","15.5","iPhone8,4","Physical","APP_VERSION","1.1"

解決策についてお書きください / Describe the solution you'd like

EventLogRepositoryのコンストラクタあたりに、ディレクトリの存在チェックと作成処理を入れる。

ただ、EventLogRepositoryはContainerに登録して、必要に応じてDryIocにより自動的にインスタンス化される。コンストラクタにI/O系の処理を入れると初期化時間が延びてアプリのパフォーマンスに影響する可能性がある。

あなたが考える代替案についてご説明ください / Describe alternatives you've considered

GetLogsAsyncInternalの冒頭にディレクトリの存在チェックを入れる。ただ、他のメソッドでも同じ処理を書く必要が出てくるので対応漏れの心配は残る。EventLogRepositoryのコンストラクタに書いてしまう方が解決策としてシンプルに思う。

その他 / Additional context


Internal IDs: -NFR 7608