1
1
import cpp
2
2
3
+ /*
4
+ * A note about how the C/C++ extractor emits diagnostics:
5
+ * When the extractor frontend encounters an error, it emits a diagnostic message,
6
+ * that includes a message, location and severity.
7
+ * However, that process is best-effort and may fail (e.g. due to lack of memory).
8
+ * Thus, if the extractor emitted at least one diagnostic of severity discretionary
9
+ * error (or higher), it *also* emits a simple "There was an error during this compilation"
10
+ * error diagnostic, without location information.
11
+ * In the common case, this means that a file with one (or more) errors also gets
12
+ * the catch-all diagnostic.
13
+ * This diagnostic has the empty string as file path.
14
+ * We filter out these useless diagnostics if there is at least one error-level diagnostic
15
+ * for the affected compilation in the database.
16
+ * Otherwise, we show it to, to indicate that something went wrong, and we
17
+ * don't know what exactly happened.
18
+ */
19
+
3
20
/**
4
- * The class of errors upon we mark a file as non-successfully extracted.
21
+ * An error that, if present, leads to a file being marked as non-successfully extracted.
5
22
*/
6
23
class ReportableError extends Diagnostic {
7
24
ReportableError ( ) {
@@ -10,13 +27,7 @@ class ReportableError extends Diagnostic {
10
27
this instanceof CompilerError or
11
28
this instanceof CompilerCatastrophe
12
29
) and
13
- // If the extractor encounters an error in a compilation, it always emits a
14
- // catch-all diagnostic "There was an error during this compilation", to ensure
15
- // that the error makes it to the database.
16
- // This error doesn't have a file path attached to it, and is thus
17
- // useless for us to report. Furthermore, in the common case, we will have a
18
- // proper diagnostic for this error we can show.
19
- // Instead, we synthesize `TUnknownError` if this is the only error that we can show to the user.
30
+ // Filter for the catch-all diagnostic, see note above.
20
31
not this .getFile ( ) .getAbsolutePath ( ) = ""
21
32
}
22
33
}
@@ -26,8 +37,11 @@ private newtype TExtractionError =
26
37
TCompilationFailed ( Compilation c , File f ) {
27
38
f = c .getAFileCompiled ( ) and not c .normalTermination ( )
28
39
} or
29
- // Report generic extractor errors only if we haven't seen any other error-level diagnostic
30
- TUnknownError ( CompilerError err ) { not exists ( ReportableError e ) }
40
+ // Show the catch-all diagnostic (see note above) only if we haven't seen any other error-level diagnostic
41
+ // for that compilation
42
+ TUnknownError ( CompilerError err ) {
43
+ not exists ( ReportableError e | e .getCompilation ( ) = err .getCompilation ( ) )
44
+ }
31
45
32
46
/**
33
47
* Superclass for the extraction error hierarchy.
@@ -53,26 +67,26 @@ class ExtractionError extends TExtractionError {
53
67
}
54
68
55
69
/**
56
- * An irrecoverable extraction failure , where extraction was unable to finish.
70
+ * An unrecoverable extraction error , where extraction was unable to finish.
57
71
* This can be caused by a multitude of reasons, for example:
58
72
* - hitting a frontend assertion
59
73
* - crashing due to dereferencing an invalid pointer
60
74
* - stack overflow
61
75
* - out of memory
62
76
*/
63
- class ExtractionIrrecoverableError extends ExtractionError , TCompilationFailed {
77
+ class ExtractionUnrecoverableError extends ExtractionError , TCompilationFailed {
64
78
Compilation c ;
65
79
File f ;
66
80
67
- ExtractionIrrecoverableError ( ) { this = TCompilationFailed ( c , f ) }
81
+ ExtractionUnrecoverableError ( ) { this = TCompilationFailed ( c , f ) }
68
82
69
83
override string toString ( ) {
70
- result = "Irrecoverable extraction error while compiling " + f .toString ( )
84
+ result = "Unrecoverable extraction error while compiling " + f .toString ( )
71
85
}
72
86
73
87
override string getErrorMessage ( ) {
74
88
result =
75
- "Irrecoverable compilation failure, check logs/build-tracer.log in the database directory for more information."
89
+ "Unrecoverable compilation failure; check logs/build-tracer.log in the database directory for more information."
76
90
}
77
91
78
92
override File getFile ( ) { result = f }
0 commit comments