@@ -35,7 +35,7 @@ import (
35
35
// patched in the package. Test packages and symbols are omitted.
36
36
//
37
37
// If the commit has more than one parent, an error is returned.
38
- func Patched (module , repoURL , commitHash string , errf logf ) (_ map [string ][]string , err error ) {
38
+ func Patched (module , repoURL , commitHash string ) (_ map [string ][]string , err error ) {
39
39
defer derrors .Wrap (& err , "Patched(%s, %s, %s)" , module , repoURL , commitHash )
40
40
41
41
repoRoot , err := os .MkdirTemp ("" , commitHash )
@@ -90,7 +90,10 @@ func Patched(module, repoURL, commitHash string, errf logf) (_ map[string][]stri
90
90
return nil , err
91
91
}
92
92
93
- patched := patchedSymbols (oldSymbols , newSymbols , errf )
93
+ patched , err := patchedSymbols (oldSymbols , newSymbols )
94
+ if err != nil {
95
+ return nil , err
96
+ }
94
97
pkgSyms := make (map [string ][]string )
95
98
for _ , sym := range patched {
96
99
pkgSyms [sym .pkg ] = append (pkgSyms [sym .pkg ], sym .symbol )
@@ -101,7 +104,7 @@ func Patched(module, repoURL, commitHash string, errf logf) (_ map[string][]stri
101
104
// patchedSymbols returns symbol indices in oldSymbols that either 1) cannot
102
105
// be identified in newSymbols or 2) the corresponding functions have their
103
106
// source code changed.
104
- func patchedSymbols (oldSymbols , newSymbols map [symKey ]* ast.FuncDecl , errf logf ) []symKey {
107
+ func patchedSymbols (oldSymbols , newSymbols map [symKey ]* ast.FuncDecl ) ( []symKey , error ) {
105
108
var syms []symKey
106
109
for key , of := range oldSymbols {
107
110
nf , ok := newSymbols [key ]
@@ -112,23 +115,30 @@ func patchedSymbols(oldSymbols, newSymbols map[symKey]*ast.FuncDecl, errf logf)
112
115
continue
113
116
}
114
117
115
- if source (of , errf ) != source (nf , errf ) {
118
+ osrc , err := source (of )
119
+ if err != nil {
120
+ return nil , err
121
+ }
122
+ nsrc , err := source (nf )
123
+ if err != nil {
124
+ return nil , err
125
+ }
126
+
127
+ if osrc != nsrc {
116
128
syms = append (syms , key )
117
129
}
118
130
}
119
- return syms
131
+ return syms , nil
120
132
}
121
133
122
134
// source returns f's source code as text.
123
- func source (f * ast.FuncDecl , errf logf ) string {
135
+ func source (f * ast.FuncDecl ) ( string , error ) {
124
136
var b bytes.Buffer
125
137
fs := token .NewFileSet ()
126
138
if err := printer .Fprint (& b , fs , f ); err != nil {
127
- // should not happen, so just printing a warning
128
- errf ("getting source of %s failed with %v" , astSymbolName (f ), err )
129
- return ""
139
+ return "" , fmt .Errorf ("getting source of %s failed: %w" , astSymbolName (f ), err )
130
140
}
131
- return strings .TrimSpace (b .String ())
141
+ return strings .TrimSpace (b .String ()), nil
132
142
}
133
143
134
144
// moduleSymbols indexes all symbols of a module located
0 commit comments