Skip to content

Commit ca6e4ee

Browse files
committed
added error checker for json.loads
1 parent 30440dd commit ca6e4ee

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

python150k/preprocess.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,20 @@ def retrieve_functions_docstrings(
316316

317317

318318
def convert_tokens_to_ast(functions):
319+
global error_counter
319320
ast_tokens = []
320321
for function in functions:
321322
if len(function) == 0:
322323
# Happens after returned TokenError
323324
# Empty function should be skipped
324325
continue
325-
ast_fun_tokens = json.loads(parse_python3.parse_file(function, "code"))
326-
ast_fun_sequential = get_dfs(convert(ast_fun_tokens))
326+
# One more option to get an error
327+
try:
328+
ast_fun_tokens = json.loads(parse_python3.parse_file(function, "code"))
329+
ast_fun_sequential = get_dfs(convert(ast_fun_tokens))
330+
except SyntaxError:
331+
error_counter += 1
332+
continue
327333
ast_tokens.append(ast_fun_sequential)
328334
return ast_tokens
329335

0 commit comments

Comments
 (0)