Skip to content

Commit 18159f0

Browse files
committed
Remove try catch around calling analysis binary
The analysis shouldn't throw, nor should JSON.parse. We don't wanna swallow them silently for now. Now they'll throw; language-server shows an alert when things throw too much. We'll see how to proceed afterward. But it's better than mysteriously failing right now.
1 parent 1ceb9d5 commit 18159f0

File tree

1 file changed

+35
-51
lines changed

1 file changed

+35
-51
lines changed

server/src/RescriptEditorSupport.ts

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,19 @@ export function runCompletionCommand(
3636
let tmpname = utils.createFileInTempDir();
3737
fs.writeFileSync(tmpname, code, { encoding: "utf-8" });
3838

39-
try {
40-
let stdout = execFileSync(
41-
binaryPath,
42-
[
43-
"complete",
44-
filePath,
45-
msg.params.position.line,
46-
msg.params.position.character,
47-
tmpname,
48-
],
49-
{ cwd: projectRootPath }
50-
);
51-
return JSON.parse(stdout.toString());
52-
} catch (error) {
53-
// TODO: @cristianoc any exception possible?
54-
return null;
55-
} finally {
56-
fs.unlink(tmpname, () => null);
57-
}
39+
let stdout = execFileSync(
40+
binaryPath,
41+
[
42+
"complete",
43+
filePath,
44+
msg.params.position.line,
45+
msg.params.position.character,
46+
tmpname,
47+
],
48+
{ cwd: projectRootPath }
49+
);
50+
fs.unlink(tmpname, () => null);
51+
return JSON.parse(stdout.toString());
5852
}
5953

6054
export function runHoverCommand(msg: RequestMessage): Hover | null {
@@ -65,22 +59,17 @@ export function runHoverCommand(msg: RequestMessage): Hover | null {
6559
return null;
6660
}
6761

68-
try {
69-
let stdout = execFileSync(
70-
binaryPath,
71-
[
72-
"hover",
73-
filePath,
74-
msg.params.position.line,
75-
msg.params.position.character,
76-
],
77-
{ cwd: projectRootPath }
78-
);
79-
return JSON.parse(stdout.toString());
80-
} catch (error) {
81-
// TODO: @cristianoc any exception possible?
82-
return null;
83-
}
62+
let stdout = execFileSync(
63+
binaryPath,
64+
[
65+
"hover",
66+
filePath,
67+
msg.params.position.line,
68+
msg.params.position.character,
69+
],
70+
{ cwd: projectRootPath }
71+
);
72+
return JSON.parse(stdout.toString());
8473
}
8574

8675
export function runDefinitionCommand(msg: RequestMessage): Location | null {
@@ -91,20 +80,15 @@ export function runDefinitionCommand(msg: RequestMessage): Location | null {
9180
return null;
9281
}
9382

94-
try {
95-
let stdout = execFileSync(
96-
binaryPath,
97-
[
98-
"definition",
99-
filePath,
100-
msg.params.position.line,
101-
msg.params.position.character,
102-
],
103-
{ cwd: projectRootPath }
104-
);
105-
return JSON.parse(stdout.toString());
106-
} catch (error) {
107-
// TODO: @cristianoc any exception possible?
108-
return null;
109-
}
83+
let stdout = execFileSync(
84+
binaryPath,
85+
[
86+
"definition",
87+
filePath,
88+
msg.params.position.line,
89+
msg.params.position.character,
90+
],
91+
{ cwd: projectRootPath }
92+
);
93+
return JSON.parse(stdout.toString());
11094
}

0 commit comments

Comments
 (0)