Skip to content

Commit f1a9f31

Browse files
committed
Remove absolute paths from test output
1 parent 50343b3 commit f1a9f31

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| 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 |
1+
| 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 |
22
| Extraction failed in modules/subdir1/test.go with error could not import subdir1/subsubdir1 (invalid package name: "") | 2 |
3-
| 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 |
3+
| 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 |
44
| Extraction failed in modules/subdir2/test.go with error could not import subdir2/subsubdir2 (invalid package name: "") | 2 |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| 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 |
1+
| 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 |
22
| Extraction failed in subdir0/subdir1/test.go with error could not import subdir1/subsubdir1 (invalid package name: "") | 2 |
3-
| 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 |
3+
| 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 |
44
| Extraction failed in subdir0/test.go with error could not import test/subdir2 (invalid package name: "") | 2 |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| 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 |
1+
| 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 |
22
| Extraction failed in subdir1/test.go with error could not import subdir1/subsubdir1 (invalid package name: "") | 2 |
3-
| 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 |
3+
| 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 |
44
| Extraction failed in subdir2/test.go with error could not import subdir2/subsubdir2 (invalid package name: "") | 2 |

go/ql/lib/semmle/go/DiagnosticsReporting.qll

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ private class Diagnostic extends @diagnostic {
3535
string toString() { result = this.getMessage() }
3636
}
3737

38+
bindingset[msg]
39+
private string removeAbsolutePaths(string msg) {
40+
exists(string r |
41+
// turn
42+
// 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)
43+
// into
44+
// 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)
45+
r =
46+
"(cannot find package [^ ]* in any of:\\n\\t)/[^ ]*(/src/[^ ]* \\(from \\$GOROOT\\)\\n\\t)/[^ ]*(/src/[^ ]* \\(from \\$GOPATH\\))" and
47+
if exists(msg.regexpCapture(r, 1))
48+
then
49+
result =
50+
msg.regexpCapture(r, 1) + "(absolute path)" + msg.regexpCapture(r, 2) + "(absolute path)" +
51+
msg.regexpCapture(r, 3)
52+
else result = msg
53+
)
54+
}
55+
3856
/**
3957
* Holds if an extraction error or warning occurred that should be reported to end users,
4058
* with the error message `msg` and SARIF severity `sev`.
@@ -47,10 +65,11 @@ predicate reportableDiagnostics(Diagnostic d, string msg, int sev) {
4765
exists(File f | f = d.getFile() |
4866
exists(f.getAChild()) and
4967
msg =
50-
"Extraction failed in " + d.getFile().getRelativePath() + " with error " + d.getMessage()
68+
"Extraction failed in " + d.getFile().getRelativePath() + " with error " +
69+
removeAbsolutePaths(d.getMessage())
5170
)
5271
or
5372
not exists(d.getFile()) and
54-
msg = "Extraction failed with error " + d.getMessage()
73+
msg = "Extraction failed with error " + removeAbsolutePaths(d.getMessage())
5574
)
5675
}

0 commit comments

Comments
 (0)