Skip to content

Commit acd8e81

Browse files
committed
refactor: return an error when the file can't be parsed
1 parent bd7e350 commit acd8e81

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/language/php-language.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,25 @@ export class PHPLanguage implements Language {
4444
};
4545
}
4646

47-
const ast = this.#engine.parseCode(file.body, file.path);
47+
try {
48+
const ast = this.#engine.parseCode(file.body, file.path);
4849

49-
return {
50-
ok: true,
51-
ast,
52-
};
50+
return {
51+
ok: true,
52+
ast,
53+
};
54+
} catch {
55+
return {
56+
ok: false,
57+
errors: [
58+
{
59+
message: 'File cannot be parsed',
60+
line: this.lineStart,
61+
column: this.columnStart,
62+
},
63+
],
64+
};
65+
}
5366
}
5467

5568
createSourceCode(file: File, input: OkParseResult<Program>) {

0 commit comments

Comments
 (0)