bildpunkt / surfbird

A Microblogging client built on Electron and Vue
MIT License
331 stars 56 forks source link

"corrupt" .surfbird file causes errors #69

Open Fubinator opened 6 years ago

Fubinator commented 6 years ago

Description

Changing the .surfbird file in different ways causes the app to throw different errors. We have to differentiate between two problems regarding this issue:

  1. The content of the .surfbird file is not valid JSON.
  2. The service object has missing/wrong data

Additional Information

Fixing the first point of the issue should be quite easy. If we take a look at the load()-method in the src/main/authentication/index.js file, we can see that the only safety check is if the file exists before parsing it to JSON. Maybe the the return of the JSON.parse function should be wrapped in a try-catch statement?

static load () {
    let file = path.join(Authentication.homePath(), '.surfbird')

    if (!fs.existsSync(file)) {
      return null
    }

    return JSON.parse(fs.readFileSync(file, 'utf-8'))
  }

For the second point we should maybe implement a check if the provided credentials are working and if not, ask the user to log in again to fix the file.

pixeldesu commented 6 years ago

I guess we can implement multiple checks here. The one you noted, catching errors on load, and maybe another one for each client (checking if the object/keys are added properly, otherwise failing)