Skip to content

Commit 6c48349

Browse files
committed
Log SemanticDB path on unexpected error
This should make it easier to troubleshoot issues
1 parent 3becc08 commit 6c48349

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

lsif-java/src/main/scala/com/sourcegraph/lsif_semanticdb/ConsoleLsifSemanticdbReporter.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import java.nio.file.NoSuchFileException
55

66
import moped.cli.Application
77
import moped.progressbars.InteractiveProgressBar
8-
import moped.reporters.Diagnostic
98

109
/**
1110
* Console reporter for index-semanticdb command.
@@ -25,7 +24,7 @@ class ConsoleLsifSemanticdbReporter(app: Application)
2524
case _: NoSuchFileException =>
2625
app.reporter.error(s"no such file: ${e.getMessage}")
2726
case _ =>
28-
app.reporter.log(Diagnostic.exception(e))
27+
e.printStackTrace(app.err)
2928
}
3029
}
3130

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.sourcegraph.lsif_semanticdb;
2+
3+
public class LsifProcessingException extends Throwable {
4+
5+
public LsifProcessingException(LsifTextDocument doc, Throwable cause) {
6+
super(doc.semanticdbPath.toString(), cause);
7+
}
8+
9+
@Override
10+
public Throwable fillInStackTrace() {
11+
return this;
12+
}
13+
}

lsif-semanticdb/src/main/java/com/sourcegraph/lsif_semanticdb/LsifSemanticdb.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,20 @@ private Set<String> exportSymbols(List<Path> files) {
8080

8181
private Stream<Integer> processPath(
8282
Path path, Set<String> isExportedSymbol, PackageTable packages) {
83-
return parseTextDocument(path).map(d -> processDocument(d, isExportedSymbol, packages));
83+
return parseTextDocument(path).flatMap(d -> processDocument(d, isExportedSymbol, packages));
8484
}
8585

86-
private Integer processDocument(
86+
private Stream<Integer> processDocument(
87+
LsifTextDocument doc, Set<String> isExportedSymbol, PackageTable packages) {
88+
try {
89+
return Stream.of(processDocumentUnsafe(doc, isExportedSymbol, packages));
90+
} catch (Exception e) {
91+
options.reporter.error(new LsifProcessingException(doc, e));
92+
return Stream.empty();
93+
}
94+
}
95+
96+
private Integer processDocumentUnsafe(
8797
LsifTextDocument doc, Set<String> isExportedSymbol, PackageTable packages) {
8898
Symtab symtab = new Symtab(doc.semanticdb);
8999

lsif-semanticdb/src/main/java/com/sourcegraph/lsif_semanticdb/SymbolDescriptor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public SymbolDescriptor(SemanticdbSymbols.Descriptor descriptor, String owner) {
1515
this.owner = owner;
1616
}
1717

18-
public static SymbolDescriptor NONE = new SymbolDescriptor(Descriptor.NONE, SemanticdbSymbols.NONE);
18+
public static SymbolDescriptor NONE =
19+
new SymbolDescriptor(Descriptor.NONE, SemanticdbSymbols.NONE);
1920

2021
public static SymbolDescriptor parseFromSymbol(String symbol) {
2122
return new Parser(symbol).entryPoint();
@@ -55,10 +56,12 @@ public Parser(String symbol) {
5556
}
5657

5758
public SymbolDescriptor entryPoint() {
58-
if (SemanticdbSymbols.isLocal(symbol))
59+
if (SemanticdbSymbols.isLocal(symbol)) {
5960
return new SymbolDescriptor(Descriptor.local(symbol), SemanticdbSymbols.NONE);
60-
if (SemanticdbSymbols.NONE.equals(symbol))
61+
}
62+
if (SemanticdbSymbols.NONE.equals(symbol)) {
6163
return SymbolDescriptor.NONE;
64+
}
6265
readChar();
6366
SemanticdbSymbols.Descriptor descriptor = parseDescriptor();
6467

0 commit comments

Comments
 (0)