Skip to content

Commit

Permalink
Added error messages for invalid JSON in config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
daverickdunn committed Oct 26, 2017
1 parent 27c5214 commit 770f926
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 6 additions & 1 deletion index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ module.exports =

activate: (state) ->
projectDict = {}
initProject(atom.project.getPaths())
try
initProject(atom.project.getPaths())
catch
atom.notifications.addError "RemoteSync Error",
{dismissable: true, detail: "Failed to initalise RemoteSync"}

CompositeDisposable ?= require('atom').CompositeDisposable
disposables = new CompositeDisposable
Expand Down Expand Up @@ -139,6 +143,7 @@ module.exports =
disposables.add onDidSave
disposables.add onDidDestroy


deactivate: ->
disposables.dispose()
disposables = null
Expand Down
9 changes: 6 additions & 3 deletions lib/RemoteSync.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RemoteSync
constructor: (@projectPath, @configPath) ->
Host ?= require './model/host'

@host = new Host(@configPath)
@host = new Host(@configPath, getLogger())
watchFiles = @host.watch?.split(",").filter(Boolean)
@projectPath = path.join(@projectPath, @host.source) if @host.source
if watchFiles?
Expand Down Expand Up @@ -112,6 +112,7 @@ class RemoteSync
uploadFolder: (dirPath)->
fs.traverseTree dirPath, @uploadFile.bind(@), =>
return not @isIgnore(dirPath)
, (->)

initMonitor: ()->
_this = @
Expand Down Expand Up @@ -243,7 +244,9 @@ class RemoteSync

fs.traverseTree dirPath, (path)=>
@uploadFile(path) if isChangedPath(path)
, (path)=> return not @isIgnore(path)
, (path) =>
return not @isIgnore(path)
, (->)

createTransport: (host)->
if host.transport is 'scp' or host.transport is 'sftp'
Expand Down Expand Up @@ -314,6 +317,6 @@ module.exports =
emitter.on "configured", callback

configPath = path.join projectPath, atom.config.get('remote-sync.configFileName')
host = new Host(configPath, emitter)
host = new Host(configPath, getLogger(), emitter)
view = new HostView(host)
view.attach()
7 changes: 5 additions & 2 deletions lib/model/host.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ EventEmitter = require("events").EventEmitter

module.exports =
class Host
constructor: (@configPath, @emitter) ->
constructor: (@configPath, @logger, @emitter) ->
return if !fs.existsSync @configPath
try
data = fs.readFileSync @configPath, "utf8"
settings = JSON.parse(data)
for k, v of settings
this[k] = v
catch err
console.log "load #{@configPath}, #{err}"
@logger.error "#{err}, in file: #{@configPath}"
atom.notifications.addError "RemoteSync Error",
{dismissable: true, detail: "#{err}", description: "#{@configPath}" }
throw error

@port?= ""
@port = @port.toString()
Expand Down

0 comments on commit 770f926

Please sign in to comment.