@@ -271,10 +271,10 @@ import (
271
271
// file system, be sure to include a cryptographic digest of the executable in
272
272
// the key to avoid version skew.
273
273
//
274
- // If the provided reportf func is non-nil, it will be used for reporting bugs
275
- // encountered during export.
276
- // TODO(rfindley): remove reportf when we are confident enough in the new
277
- // objectpath encoding .
274
+ // If the provided reportf func is non-nil, it is used for reporting
275
+ // bugs (e.g. recovered panics) encountered during export, enabling us
276
+ // to obtain via telemetry the stack that would otherwise be lost by
277
+ // merely returning an error .
278
278
func IExportShallow (fset * token.FileSet , pkg * types.Package , reportf ReportFunc ) ([]byte , error ) {
279
279
// In principle this operation can only fail if out.Write fails,
280
280
// but that's impossible for bytes.Buffer---and as a matter of
@@ -283,7 +283,7 @@ func IExportShallow(fset *token.FileSet, pkg *types.Package, reportf ReportFunc)
283
283
// TODO(adonovan): use byte slices throughout, avoiding copying.
284
284
const bundle , shallow = false , true
285
285
var out bytes.Buffer
286
- err := iexportCommon (& out , fset , bundle , shallow , iexportVersion , []* types.Package {pkg })
286
+ err := iexportCommon (& out , fset , bundle , shallow , iexportVersion , []* types.Package {pkg }, reportf )
287
287
return out .Bytes (), err
288
288
}
289
289
@@ -323,20 +323,27 @@ const bundleVersion = 0
323
323
// so that calls to IImportData can override with a provided package path.
324
324
func IExportData (out io.Writer , fset * token.FileSet , pkg * types.Package ) error {
325
325
const bundle , shallow = false , false
326
- return iexportCommon (out , fset , bundle , shallow , iexportVersion , []* types.Package {pkg })
326
+ return iexportCommon (out , fset , bundle , shallow , iexportVersion , []* types.Package {pkg }, nil )
327
327
}
328
328
329
329
// IExportBundle writes an indexed export bundle for pkgs to out.
330
330
func IExportBundle (out io.Writer , fset * token.FileSet , pkgs []* types.Package ) error {
331
331
const bundle , shallow = true , false
332
- return iexportCommon (out , fset , bundle , shallow , iexportVersion , pkgs )
332
+ return iexportCommon (out , fset , bundle , shallow , iexportVersion , pkgs , nil )
333
333
}
334
334
335
- func iexportCommon (out io.Writer , fset * token.FileSet , bundle , shallow bool , version int , pkgs []* types.Package ) (err error ) {
335
+ func iexportCommon (out io.Writer , fset * token.FileSet , bundle , shallow bool , version int , pkgs []* types.Package , reportf ReportFunc ) (err error ) {
336
336
if ! debug {
337
337
defer func () {
338
338
if e := recover (); e != nil {
339
+ // Report the stack via telemetry (see #71067).
340
+ if reportf != nil {
341
+ reportf ("panic in exporter" )
342
+ }
339
343
if ierr , ok := e .(internalError ); ok {
344
+ // internalError usually means we exported a
345
+ // bad go/types data structure: a violation
346
+ // of an implicit precondition of Export.
340
347
err = ierr
341
348
return
342
349
}
0 commit comments