mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
Remove absolute paths from test output
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
| Extraction failed in modules/subdir1/test.go with error cannot find package "subdir1/subsubdir1" in any of:\n\t/usr/local/Cellar/go/1.20.5/libexec/src/subdir1/subsubdir1 (from $GOROOT)\n\t/Users/owen-mc/go/src/subdir1/subsubdir1 (from $GOPATH) | 2 |
|
||||
| Extraction failed in modules/subdir1/test.go with error cannot find package "subdir1/subsubdir1" in any of:\n\t(absolute path)/src/subdir1/subsubdir1 (from $GOROOT)\n\t(absolute path)/src/subdir1/subsubdir1 (from $GOPATH) | 2 |
|
||||
| Extraction failed in modules/subdir1/test.go with error could not import subdir1/subsubdir1 (invalid package name: "") | 2 |
|
||||
| Extraction failed in modules/subdir2/test.go with error cannot find package "subdir2/subsubdir2" in any of:\n\t/usr/local/Cellar/go/1.20.5/libexec/src/subdir2/subsubdir2 (from $GOROOT)\n\t/Users/owen-mc/go/src/subdir2/subsubdir2 (from $GOPATH) | 2 |
|
||||
| Extraction failed in modules/subdir2/test.go with error cannot find package "subdir2/subsubdir2" in any of:\n\t(absolute path)/src/subdir2/subsubdir2 (from $GOROOT)\n\t(absolute path)/src/subdir2/subsubdir2 (from $GOPATH) | 2 |
|
||||
| Extraction failed in modules/subdir2/test.go with error could not import subdir2/subsubdir2 (invalid package name: "") | 2 |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
| Extraction failed in subdir0/subdir1/test.go with error cannot find package "subdir1/subsubdir1" in any of:\n\t/usr/local/Cellar/go/1.20.5/libexec/src/subdir1/subsubdir1 (from $GOROOT)\n\t/Users/owen-mc/go/src/subdir1/subsubdir1 (from $GOPATH) | 2 |
|
||||
| Extraction failed in subdir0/subdir1/test.go with error cannot find package "subdir1/subsubdir1" in any of:\n\t(absolute path)/src/subdir1/subsubdir1 (from $GOROOT)\n\t(absolute path)/src/subdir1/subsubdir1 (from $GOPATH) | 2 |
|
||||
| Extraction failed in subdir0/subdir1/test.go with error could not import subdir1/subsubdir1 (invalid package name: "") | 2 |
|
||||
| Extraction failed in subdir0/test.go with error cannot find package "test/subdir2" in any of:\n\t/usr/local/Cellar/go/1.20.5/libexec/src/test/subdir2 (from $GOROOT)\n\t/Users/owen-mc/go/src/test/subdir2 (from $GOPATH) | 2 |
|
||||
| Extraction failed in subdir0/test.go with error cannot find package "test/subdir2" in any of:\n\t(absolute path)/src/test/subdir2 (from $GOROOT)\n\t(absolute path)/src/test/subdir2 (from $GOPATH) | 2 |
|
||||
| Extraction failed in subdir0/test.go with error could not import test/subdir2 (invalid package name: "") | 2 |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
| Extraction failed in subdir1/test.go with error cannot find package "subdir1/subsubdir1" in any of:\n\t/usr/local/Cellar/go/1.20.5/libexec/src/subdir1/subsubdir1 (from $GOROOT)\n\t/Users/owen-mc/go/src/subdir1/subsubdir1 (from $GOPATH) | 2 |
|
||||
| Extraction failed in subdir1/test.go with error cannot find package "subdir1/subsubdir1" in any of:\n\t(absolute path)/src/subdir1/subsubdir1 (from $GOROOT)\n\t(absolute path)/src/subdir1/subsubdir1 (from $GOPATH) | 2 |
|
||||
| Extraction failed in subdir1/test.go with error could not import subdir1/subsubdir1 (invalid package name: "") | 2 |
|
||||
| Extraction failed in subdir2/test.go with error cannot find package "subdir2/subsubdir2" in any of:\n\t/usr/local/Cellar/go/1.20.5/libexec/src/subdir2/subsubdir2 (from $GOROOT)\n\t/Users/owen-mc/go/src/subdir2/subsubdir2 (from $GOPATH) | 2 |
|
||||
| Extraction failed in subdir2/test.go with error cannot find package "subdir2/subsubdir2" in any of:\n\t(absolute path)/src/subdir2/subsubdir2 (from $GOROOT)\n\t(absolute path)/src/subdir2/subsubdir2 (from $GOPATH) | 2 |
|
||||
| Extraction failed in subdir2/test.go with error could not import subdir2/subsubdir2 (invalid package name: "") | 2 |
|
||||
|
||||
@@ -35,6 +35,24 @@ private class Diagnostic extends @diagnostic {
|
||||
string toString() { result = this.getMessage() }
|
||||
}
|
||||
|
||||
bindingset[msg]
|
||||
private string removeAbsolutePaths(string msg) {
|
||||
exists(string r |
|
||||
// turn
|
||||
// cannot find package "subdir1/subsubdir1" in any of:\n\t/usr/local/Cellar/go/1.20.5/libexec/src/subdir1/subsubdir1 (from $GOROOT)\n\t/Users/owen-mc/go/src/subdir1/subsubdir1 (from $GOPATH)
|
||||
// into
|
||||
// cannot find package "subdir1/subsubdir1" in any of:\n\t(absolute path)/src/subdir1/subsubdir1 (from $GOROOT)\n\t(absolute path)/src/subdir1/subsubdir1 (from $GOPATH)
|
||||
r =
|
||||
"(cannot find package [^ ]* in any of:\\n\\t)/[^ ]*(/src/[^ ]* \\(from \\$GOROOT\\)\\n\\t)/[^ ]*(/src/[^ ]* \\(from \\$GOPATH\\))" and
|
||||
if exists(msg.regexpCapture(r, 1))
|
||||
then
|
||||
result =
|
||||
msg.regexpCapture(r, 1) + "(absolute path)" + msg.regexpCapture(r, 2) + "(absolute path)" +
|
||||
msg.regexpCapture(r, 3)
|
||||
else result = msg
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if an extraction error or warning occurred that should be reported to end users,
|
||||
* with the error message `msg` and SARIF severity `sev`.
|
||||
@@ -47,10 +65,11 @@ predicate reportableDiagnostics(Diagnostic d, string msg, int sev) {
|
||||
exists(File f | f = d.getFile() |
|
||||
exists(f.getAChild()) and
|
||||
msg =
|
||||
"Extraction failed in " + d.getFile().getRelativePath() + " with error " + d.getMessage()
|
||||
"Extraction failed in " + d.getFile().getRelativePath() + " with error " +
|
||||
removeAbsolutePaths(d.getMessage())
|
||||
)
|
||||
or
|
||||
not exists(d.getFile()) and
|
||||
msg = "Extraction failed with error " + d.getMessage()
|
||||
msg = "Extraction failed with error " + removeAbsolutePaths(d.getMessage())
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user