Skip to content

Commit 6b6adad

Browse files
authored
Merge pull request #257 from ethereum/refactor-api
Add safeguard(s) in compileStandardWrapper for some edge cases
2 parents be32d4a + 7be3353 commit 6b6adad

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

wrapper.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ function setupMethods (soljson) {
116116
return formatFatalError('Invalid import callback supplied');
117117
}
118118

119-
input = JSON.parse(input);
119+
try {
120+
input = JSON.parse(input);
121+
} catch (e) {
122+
return formatFatalError('Invalid JSON supplied: ' + e.message);
123+
}
120124

121125
if (input['language'] !== 'Solidity') {
122126
return formatFatalError('Only Solidity sources are supported');
@@ -155,7 +159,12 @@ function setupMethods (soljson) {
155159
}
156160

157161
function translateOutput (output) {
158-
output = translate.translateJsonCompilerOutput(JSON.parse(output));
162+
try {
163+
output = JSON.parse(output);
164+
} catch (e) {
165+
return formatFatalError('Compiler returned invalid JSON: ' + e.message);
166+
}
167+
output = translate.translateJsonCompilerOutput(output);
159168
if (output == null) {
160169
return formatFatalError('Failed to process output');
161170
}
@@ -180,7 +189,11 @@ function setupMethods (soljson) {
180189
}
181190

182191
// Try our luck with an ancient compiler
183-
return translateOutput(compileJSON(sources[Object.keys(sources)[0]], isOptimizerEnabled(input)), libraries);
192+
if (compileJSON !== null) {
193+
return translateOutput(compileJSON(sources[Object.keys(sources)[0]], isOptimizerEnabled(input)), libraries);
194+
}
195+
196+
return formatFatalError('Compiler does not support any known interface.');
184197
};
185198

186199
var version;

0 commit comments

Comments
 (0)