Skip to content

Commit d7bc55f

Browse files
authored
Merge pull request #699 from JunoLab/sp/fixcrashes
Fix Atom crashes on Windows
2 parents 3bdfcfa + 5e4a300 commit d7bc55f

File tree

14 files changed

+131
-89
lines changed

14 files changed

+131
-89
lines changed

lib/connection.coffee

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
{time} = require './misc'
22
externalTerminal = require './connection/terminal'
33

4-
metrics = ->
5-
if id = localStorage.getItem 'metrics.userId'
6-
r = require('http').get "http://data.junolab.org/hit?id=#{id}&app=atom-julia-boot"
7-
r.on 'error', ->
8-
94
module.exports =
105
IPC: require './connection/ipc'
116
messages: require './connection/messages'
@@ -48,8 +43,7 @@ module.exports =
4843
@booting = false
4944
p.catch =>
5045
@booting = false
51-
time "Julia Boot", @client.import('ping')().then =>
52-
metrics()
46+
time "Julia Boot", @client.import('ping')()
5347

5448
bootRemote: ->
5549
@_boot('Remote')

lib/connection/client.coffee

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
IPC = require './ipc'
55

6-
metrics = throttle metrics, 60*60*1000
7-
86
module.exports =
97

108
# Connection logic injects a connection via `attach`.

lib/connection/local.coffee

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,7 @@ module.exports =
3737
@provider().start? paths.jlpath(), client.clargs()
3838
.catch ->
3939

40-
monitorExit: (proc) ->
41-
proc.onExit (code, signal) ->
42-
msg = "Julia has stopped"
43-
if not proc.wrapper and code isnt 0
44-
msg += ": #{code}"
45-
if signal then msg += ", #{signal}"
46-
else
47-
msg += "."
48-
client.info msg
49-
50-
pipeStreams: (proc) ->
51-
out = (data) -> client.stdout data.toString()
52-
err = (data) -> client.stderr data.toString()
53-
proc.flush? out, err
54-
proc.onStdout out
55-
proc.onStderr err
56-
5740
monitor: (proc) ->
58-
proc.ready = -> false
59-
@pipeStreams proc
60-
@monitorExit proc
61-
client.attach proc
62-
proc
63-
64-
monitor2: (proc) ->
6541
client.emitter.emit('boot', proc)
6642
proc.ready = -> false
6743
client.attach(proc)
@@ -92,7 +68,7 @@ module.exports =
9268

9369
proc = check
9470
.then => @spawnJulia(path, args, provider)
95-
.then (proc) => if proc.ty? then @monitor2(proc) else @monitor(proc)
71+
.then (proc) => @monitor(proc)
9672

9773
# set working directory here, so we queue this task before anything else
9874
if provider is 'Remote'

lib/connection/process/basic.js

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function get (path, args) {
2020

2121
export function get_ (path, args) {
2222
const env = customEnv()
23-
return getUnix(path, args, env)
23+
return getProcess(path, args, env)
2424
}
2525

2626
export function customEnv (env = process.env) {
@@ -43,7 +43,7 @@ export function customEnv (env = process.env) {
4343
return env
4444
}
4545

46-
function getUnix (path, args, env) {
46+
function getProcess (path, args, env) {
4747
return new Promise((resolve, reject) => {
4848
tcp.listen().then((port) => {
4949
paths.fullPath(path).then((path) => {
@@ -54,21 +54,56 @@ function getUnix (path, args, env) {
5454
rows: 30,
5555
env: env,
5656
cwd: cwd,
57-
useConpty: true
57+
useConpty: true,
58+
handleFlowControl: true
5859
})
5960

6061
let sock = socket(ty)
6162

62-
sock.catch((err) => reject(err))
63+
sock.catch((err) => {
64+
reject(err)
65+
})
6366

67+
// catch errors when interacting with ty, just to be safe (errors might crash Atom)
6468
let proc = {
6569
ty: ty,
66-
kill: () => ty.kill(),
67-
interrupt: () => ty.write('\x03'),
70+
kill: () => {
71+
// only kill pty if it's still alive:
72+
if (ty._readable || ty._writable) {
73+
try {
74+
ty.kill()
75+
} catch (err) {
76+
console.log('Terminal:')
77+
console.log(err);
78+
}
79+
}
80+
},
81+
interrupt: () => {
82+
try {
83+
ty.write('\x03')
84+
} catch (err) {
85+
console.log('Terminal:')
86+
console.log(err);
87+
}
88+
},
6889
socket: sock,
69-
onExit: (f) => ty.on('exit', f),
90+
onExit: (f) => {
91+
try {
92+
ty.on('exit', f)
93+
} catch (err) {
94+
console.log('Terminal:')
95+
console.log(err);
96+
}
97+
},
7098
onStderr: (f) => {},
71-
onStdout: (f) => ty.on('data', f)
99+
onStdout: (f) => {
100+
try {
101+
ty.on('data', f)
102+
} catch (err) {
103+
console.log('Terminal:')
104+
console.log(err);
105+
}
106+
}
72107
}
73108

74109
resolve(proc)
@@ -84,17 +119,6 @@ function getUnix (path, args, env) {
84119
})
85120
}
86121

87-
function freePort() {
88-
return new Promise((resolve) => {
89-
let server = net.createServer()
90-
server.listen(0, '127.0.0.1', () => {
91-
let port = server.address().port
92-
server.close()
93-
resolve(port)
94-
})
95-
})
96-
}
97-
98122
function socket (ty) {
99123
conn = tcp.next()
100124
failure = new Promise((resolve, reject) => {

lib/connection/process/remote.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function get (path, args) {
1717
return lock((release) => {
1818
let p = get_(path, args)
1919
release(p.then(({socket}) => socket))
20+
p.catch(() => release())
2021
return p
2122
})
2223
}

lib/runtime/completions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class AutoCompleteProvider {
112112
completion.description = ' '
113113
}
114114
return completion
115+
}).catch(err => {
116+
console.log(err)
115117
})
116118
return Promise.race([completionWithDetail, this.sleep()])
117119
}

lib/runtime/console.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ function newTerminal (cwd) {
185185
term.setDefaultLocation(atom.config.get('julia-client.uiOptions.layouts.terminal.defaultLocation'))
186186
term.open({
187187
split: atom.config.get('julia-client.uiOptions.layouts.terminal.split')
188-
}).then(() => term.show())
188+
}).then(() => term.show()).catch(err => {
189+
console.log(err)
190+
})
189191
}).catch(() => {})
190192
}
191193

@@ -334,14 +336,16 @@ function shellPty (cwd) {
334336
cwd = paths.home()
335337
}
336338
const env = customEnv()
339+
const ty = pty.spawn(atom.config.get("julia-client.consoleOptions.shell"), [], {
340+
cols: 100,
341+
rows: 30,
342+
cwd: cwd,
343+
env: env,
344+
useConpty: true,
345+
handleFlowControl: true
346+
})
337347
resolve({
338-
pty: pty.fork(atom.config.get("julia-client.consoleOptions.shell"), [], {
339-
cols: 100,
340-
rows: 30,
341-
cwd: cwd,
342-
env: env,
343-
useConpty: true
344-
}),
348+
pty: ty,
345349
cwd: cwd})
346350
} else {
347351
reject()

lib/runtime/debugger.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ export function debugFile(shouldStep, el) {
225225
const data = { path, code, row: 1, column: 1 }
226226
getmodule(data).then(mod => {
227227
debugfile(modules.current(mod), code, path, shouldStep)
228+
}).catch(err => {
229+
console.log(err)
228230
})
229231
} catch (err) {
230232
atom.notifications.addError('Error happened', {

lib/runtime/evaluation.coffee

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,21 @@ module.exports =
8787
code: code
8888
row: 1
8989
column: 1
90-
getmodule(data).then (mod) =>
91-
evalall({
92-
path: path
93-
module: modules.current mod
94-
code: code
95-
}).then (result) ->
96-
notifications.show "Evaluation Finished"
97-
workspace.update()
90+
getmodule(data)
91+
.then (mod) =>
92+
evalall({
93+
path: path
94+
module: modules.current mod
95+
code: code
96+
})
97+
.then (result) ->
98+
notifications.show "Evaluation Finished"
99+
workspace.update()
100+
.catch (err) =>
101+
console.log(err)
102+
.catch (err) =>
103+
console.log(err)
104+
98105
catch error
99106
atom.notifications.addError 'Error happened',
100107
detail: error
@@ -110,9 +117,12 @@ module.exports =
110117
path: edpath
111118
module: module
112119
code: code
113-
}).then (result) ->
114-
notifications.show "Evaluation Finished"
115-
workspace.update()
120+
})
121+
.then (result) ->
122+
notifications.show "Evaluation Finished"
123+
workspace.update()
124+
.catch (err) =>
125+
console.log(err)
116126

117127
toggleDocs: () ->
118128
{ editor, mod, edpath } = @_currentContext()
@@ -123,18 +133,21 @@ module.exports =
123133
word = editor.getTextInBufferRange(range)
124134

125135
return unless words.isValidWordToInspect(word)
126-
searchDoc({word: word, mod: mod}).then (result) =>
127-
if result.error then return
128-
v = views.render result
129-
processLinks(v.getElementsByTagName('a'))
130-
if atom.config.get('julia-client.uiOptions.docsDisplayMode') == 'inline'
131-
d = new @ink.InlineDoc editor, range,
132-
content: v
133-
highlight: true
134-
d.view.classList.add 'julia'
135-
else
136-
docpane.ensureVisible()
137-
docpane.showDocument(v, [])
136+
searchDoc({word: word, mod: mod})
137+
.then (result) =>
138+
if result.error then return
139+
v = views.render result
140+
processLinks(v.getElementsByTagName('a'))
141+
if atom.config.get('julia-client.uiOptions.docsDisplayMode') == 'inline'
142+
d = new @ink.InlineDoc editor, range,
143+
content: v
144+
highlight: true
145+
d.view.classList.add 'julia'
146+
else
147+
docpane.ensureVisible()
148+
docpane.showDocument(v, [])
149+
.catch (err) =>
150+
console.log(err)
138151

139152
# Working Directory
140153

@@ -177,9 +190,12 @@ module.exports =
177190
else if dirs.length == 1
178191
@_cd dirs[0]
179192
else
180-
selector.show(dirs).then (dir) =>
181-
return unless dir?
182-
@_cd dir
193+
selector.show(dirs)
194+
.then (dir) =>
195+
return unless dir?
196+
@_cd dir
197+
.catch (err) =>
198+
console.log(err)
183199

184200
cdHome: ->
185201
@_cd paths.home()

lib/runtime/formatter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ function formatEditorTextInRange (editor, range, text) {
6060
})
6161
}
6262
}
63+
}).catch(err => {
64+
console.log(err)
6365
}).finally(() => {
6466
marker.destroy()
6567
})
@@ -92,7 +94,11 @@ export function activate() {
9294
edWatch.delete(ed)
9395
ed.save().then(() => {
9496
edWatch.add(ed)
97+
}).catch(err => {
98+
console.log(err)
9599
})
100+
}).catch(err => {
101+
console.log(err)
96102
})
97103
}
98104
}

0 commit comments

Comments
 (0)