philosowaffle / peloton-to-garmin

Convert workout data from Peloton into JSON/TCX/FIT files and automatically upload to Garmin Connect
https://philosowaffle.github.io/peloton-to-garmin/
GNU General Public License v3.0
276 stars 364 forks source link

On V2 branch, from clean ZIP install, missing an empty syncHistory.json causes an exception #105

Closed jsmrcina closed 3 years ago

jsmrcina commented 3 years ago

Downloading the distribution ZIP from latest V2 branch, unzipping and configuring using the configuration JSON and then running the console app will crash with a file not found exception when looking for the syncHistory.json file as it does not exist.

To workaround, you must create the DB file by hand and put an empty JSON object into it:

.\output\syncHistory.json

{}

Note that path may need to be adjusted if the configuration file property SyncHistoryDbPath was changed. Once this file exists, the sync runs as expected.

Also note that this only seems to happen on first run. If I delete the syncHistory.json file after a sync is finished, it will re-create the file correctly.

One final detail is that the directory does exist (even though the exception claims it is a directory missing error) -- only the file is missing:

PS C:\P2G> dir output
    Directory: C:\P2G\output

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         5/3/2021   8:22 PM           1520 log20210503.txt

Exception text is below:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\P2G\output\syncHistory.json'.
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks)
   at System.IO.File.InternalReadAllText(String path, Encoding encoding)
   at System.IO.File.ReadAllText(String path)
   at JsonFlatFileDataStore.DataStore.ReadJsonFromFile(String path)
   at JsonFlatFileDataStore.DataStore..ctor(String path, Boolean useLowerCamelCase, String keyProperty, Boolean reloadBeforeGetCollection)
   at Common.Database.DbClient..ctor(Configuration configuration) in /home/runner/work/peloton-to-garmin/peloton-to-garmin/src/Common/Database/DbClient.cs:line 27
   at PelotonToGarminConsole.Program.RunAsync(Configuration config) in /home/runner/work/peloton-to-garmin/peloton-to-garmin/src/PelotonToGarminConsole/Program.cs:line 120
   at PelotonToGarminConsole.Program.Main(String[] args) in /home/runner/work/peloton-to-garmin/peloton-to-garmin/src/PelotonToGarminConsole/Program.cs:line 93
Unhandled exception. System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\P2G\output\syncHistory.json'.
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks)
   at System.IO.File.InternalReadAllText(String path, Encoding encoding)
   at System.IO.File.ReadAllText(String path)
   at JsonFlatFileDataStore.DataStore.ReadJsonFromFile(String path)
   at JsonFlatFileDataStore.DataStore..ctor(String path, Boolean useLowerCamelCase, String keyProperty, Boolean reloadBeforeGetCollection)
   at Common.Database.DbClient..ctor(Configuration configuration) in /home/runner/work/peloton-to-garmin/peloton-to-garmin/src/Common/Database/DbClient.cs:line 27
   at PelotonToGarminConsole.Program.RunAsync(Configuration config) in /home/runner/work/peloton-to-garmin/peloton-to-garmin/src/PelotonToGarminConsole/Program.cs:line 120
   at PelotonToGarminConsole.Program.Main(String[] args) in /home/runner/work/peloton-to-garmin/peloton-to-garmin/src/PelotonToGarminConsole/Program.cs:line 93
jsmrcina commented 3 years ago

A bit more testing shows that this is actually due to the output directory not being present when the program launches. The directory is then created for the log file so if you re-run the binary, it will create the syncHistory.json file automatically.

I think the fix here is just to pre-create the output directory if it doesn't exist when reading the configuration.

philosowaffle commented 3 years ago

Thanks for the two bugs! I can definitely fix both of these, however, I have family in town for the next week so my free time to address these may be limited. But know they are on my radar!

jsmrcina commented 3 years ago

No problem -- happy to help and there's no rush here. When you get a chance to look, please let me know if you have any trouble repro'ing and I can provide additional details as necessary. Have a great week with your family!

philosowaffle commented 3 years ago

Fix for this has been pushed. Please open a new ticket if you continue to observe the issue.