|
25 | 25 | import org.openrewrite.python.marker.PythonResolutionResult; |
26 | 26 | import org.openrewrite.python.marker.PythonResolutionResult.Dependency; |
27 | 27 | import org.openrewrite.python.marker.PythonResolutionResult.ResolvedDependency; |
| 28 | +import org.openrewrite.marker.Markers; |
28 | 29 | import org.openrewrite.python.tree.Py; |
29 | 30 | import org.openrewrite.rpc.RewriteRpc; |
30 | 31 | import org.openrewrite.rpc.RewriteRpcProcess; |
31 | 32 | import org.openrewrite.rpc.RewriteRpcProcessManager; |
| 33 | +import org.openrewrite.tree.ParseError; |
32 | 34 | import org.openrewrite.tree.ParsingEventListener; |
33 | 35 | import org.openrewrite.tree.ParsingExecutionContextView; |
34 | 36 |
|
|
41 | 43 | import java.io.InputStream; |
42 | 44 | import java.io.PrintStream; |
43 | 45 | import java.io.UncheckedIOException; |
| 46 | +import java.nio.charset.StandardCharsets; |
44 | 47 | import java.nio.file.Files; |
45 | 48 | import java.nio.file.Path; |
46 | 49 | import java.nio.file.Paths; |
@@ -204,9 +207,24 @@ public boolean tryAdvance(Consumer<? super SourceFile> action) { |
204 | 207 | ParseProjectResponse.Item item = response.get(index); |
205 | 208 | index++; |
206 | 209 |
|
207 | | - SourceFile sourceFile = getObject(item.getId(), item.getSourceFileType()); |
208 | | - // for status update messages |
209 | | - parsingListener.startedParsing(Parser.Input.fromFile(sourceFile.getSourcePath())); |
| 210 | + SourceFile sourceFile; |
| 211 | + try { |
| 212 | + sourceFile = getObject(item.getId(), item.getSourceFileType()); |
| 213 | + parsingListener.startedParsing(Parser.Input.fromFile(sourceFile.getSourcePath())); |
| 214 | + } catch (Exception e) { |
| 215 | + sourceFile = new ParseError( |
| 216 | + Tree.randomId(), |
| 217 | + new Markers(Tree.randomId(), Collections.singletonList( |
| 218 | + ParseExceptionResult.build(PythonParser.class, e, null))), |
| 219 | + Paths.get(item.getSourcePath()), |
| 220 | + null, |
| 221 | + StandardCharsets.UTF_8.name(), |
| 222 | + false, |
| 223 | + null, |
| 224 | + e.getMessage(), |
| 225 | + null |
| 226 | + ); |
| 227 | + } |
210 | 228 | action.accept(sourceFile); |
211 | 229 | return true; |
212 | 230 | } |
|
0 commit comments