swdotcom / swdc-atom-music-time

An Atom package to discover the most productive music to listen to as you code
https://www.software.com/music-time
Apache License 2.0
3 stars 1 forks source link

Exception after installing #25

Open AndreasPizsa opened 4 years ago

AndreasPizsa commented 4 years ago

Describe the bug A clear and concise description of what the bug is.

/Users/apizsa/.atom/packages/code-time/lib/UtilManager.js:255 Uncaught (in promise) SyntaxError: Unexpected string in JSON at position 15
    at JSON.parse (<anonymous>)
    at Object.utilMgr.getSoftwareSessionAsJson (/Users/apizsa/.atom/packages/code-time/lib/UtilManager.js:249)
    at Object.utilMgr.getItem (/Users/apizsa/.atom/packages/code-time/lib/UtilManager.js:237)
    at Object.utilMgr.jwtExists (/Users/apizsa/.atom/packages/code-time/lib/UtilManager.js:256)
    at Object.<anonymous> (/Users/apizsa/.atom/packages/code-time/lib/Activator.js:36)
    at Generator.next (<anonymous>)
    at step (/Users/apizsa/.atom/packages/code-time/lib/Activator.js:5)
/Users/apizsa/.atom/packages/music-time/lib/FileUtil.js:56 Uncaught (in promise) SyntaxError: Unexpected string in JSON at position 15
    at JSON.parse (<anonymous>)
    at Object.fileUtil.getSoftwareSessionAsJson (/Users/apizsa/.atom/packages/music-time/lib/FileUtil.js:56)
    at Object.fileUtil.getItem (/Users/apizsa/.atom/packages/music-time/lib/FileUtil.js:79)
    at Object.utilMgr.jwtExists (/Users/apizsa/.atom/packages/music-time/lib/UtilManager.js:276)
    at Object.<anonymous> (/Users/apizsa/.atom/packages/music-time/lib/Activator.js:49)
    at Generator.next (<anonymous>)
    at step (/Users/apizsa/.atom/packages/music-time/lib/Activator.js:7)

ISSUE TYPE

Steps to reproduce

  1. Install it in Atom
  2. Close Atom Settings
  3. Menu: View -> Toggle Command Pallette
  4. Type "swdc-atom-music-time" (or try to find swdc-atom-music-time)
  5. it’s not there!
  6. Assume something failed during initialization
  7. View -> Developer -> Toggle Developer Tools
  8. Look in console
  9. See exceptions

Expected behavior A clear and concise description of what you expected to happen.

I expected swdc-atom-music-time to be initialized and visible in Atom

ACTUAL RESULTS

/Users/apizsa/.atom/packages/code-time/lib/UtilManager.js:255 Uncaught (in promise) SyntaxError: Unexpected string in JSON at position 15
    at JSON.parse (<anonymous>)
    at Object.utilMgr.getSoftwareSessionAsJson (/Users/apizsa/.atom/packages/code-time/lib/UtilManager.js:249)
    at Object.utilMgr.getItem (/Users/apizsa/.atom/packages/code-time/lib/UtilManager.js:237)
    at Object.utilMgr.jwtExists (/Users/apizsa/.atom/packages/code-time/lib/UtilManager.js:256)
    at Object.<anonymous> (/Users/apizsa/.atom/packages/code-time/lib/Activator.js:36)
    at Generator.next (<anonymous>)
    at step (/Users/apizsa/.atom/packages/code-time/lib/Activator.js:5)
/Users/apizsa/.atom/packages/music-time/lib/FileUtil.js:56 Uncaught (in promise) SyntaxError: Unexpected string in JSON at position 15
    at JSON.parse (<anonymous>)
    at Object.fileUtil.getSoftwareSessionAsJson (/Users/apizsa/.atom/packages/music-time/lib/FileUtil.js:56)
    at Object.fileUtil.getItem (/Users/apizsa/.atom/packages/music-time/lib/FileUtil.js:79)
    at Object.utilMgr.jwtExists (/Users/apizsa/.atom/packages/music-time/lib/UtilManager.js:276)
    at Object.<anonymous> (/Users/apizsa/.atom/packages/music-time/lib/Activator.js:49)
    at Generator.next (<anonymous>)
    at step (/Users/apizsa/.atom/packages/music-time/lib/Activator.js:7)

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

It‘s trying to parse the contents of `/Users/username/.software/session.json`.

Looking at that file, it’s pretty malformed :)

{"wctime":1770}"currentDay":"2020-04-02","latestPayloadTimestampEndUtc":0}

That’s not JSON, and I don’t quite know how this ended up there.
xavluiz commented 4 years ago

Thank you for the issue update. We'll look into this immediately and apologize for the inconvenience.

AndreasPizsa commented 4 years ago

Additional info: I've had Code Time installed before for a while; could be that Code Time screwed up that file.

xavluiz commented 4 years ago

That is helpful to know, thank you. Investigating now and will provide more information soon.

xavluiz commented 4 years ago

We've identified a possible cause and will have a new version of music time and code time available within the day. One last question to confirm some of our understandings, do you think you may have had multiple Atom windows open during install?

xavluiz commented 4 years ago

We've updated code time and music time with the following versions.

code-time@v4.1.8 music-time@v2.0.7

The session.json file is no longer valid, as you mentioned, and will need to be recreated. Can you delete your ~/.software folder then upgrade? Thank you.

AndreasPizsa commented 4 years ago

do you think you may have had multiple Atom windows open during install?

I’m not 100% sure, but that’s more than likely.

AndreasPizsa commented 4 years ago

Can you delete your ~/.software folder then upgrade?

I fixed the malformed JSON instead; it‘s working now, thanks!

AndreasPizsa commented 4 years ago

It just happened again.

❯ cat ~/.software/session.json
{"wctime":30,"currentDay":"2020-06-23"}"latestPayloadTimestampEndUtc":0}

something seems to keep messing up this file.

code-time 4.1.9 music-time 2.0.8

No exception this time. But neither code-time nor music-time would show up in the Command Palette.

xavluiz commented 4 years ago

We'll look into this today and let you know as soon as we can. Do you have any other editors using Code Time and Music Time besides Atom? Thank you.

xavluiz commented 4 years ago

We've updated atom music time and code time to handle read and writes for this type of use case. There may be time when both plugins are utilizing the session.json and corruption would occur. The logic around this will now look into a short lived cache before accessing the file for any info. It will also keep a valid session json in memory but will be replace when either plugin or multiple windows update the session.

code-time@v4.1.11 music-time@v2.0.10

Thank you.