mirror of
https://github.com/golang/go
synced 2024-09-30 22:48:32 -06:00
go/importer: better error messages when export data is not found
Fixes #17281. Change-Id: I4e639998dbe3baa98879f1becc37d7c4d19351e7 Reviewed-on: https://go-review.googlesource.com/30473 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
8aadcc551e
commit
33faa4ebb9
@ -8,7 +8,6 @@ package gcimporter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -29,7 +28,7 @@ func readGopackHeader(r *bufio.Reader) (name string, size int, err error) {
|
|||||||
s := strings.TrimSpace(string(hdr[16+12+6+6+8:][:10]))
|
s := strings.TrimSpace(string(hdr[16+12+6+6+8:][:10]))
|
||||||
size, err = strconv.Atoi(s)
|
size, err = strconv.Atoi(s)
|
||||||
if err != nil || hdr[len(hdr)-2] != '`' || hdr[len(hdr)-1] != '\n' {
|
if err != nil || hdr[len(hdr)-2] != '`' || hdr[len(hdr)-1] != '\n' {
|
||||||
err = errors.New("invalid archive header")
|
err = fmt.Errorf("invalid archive header")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
name = strings.TrimSpace(string(hdr[:16]))
|
name = strings.TrimSpace(string(hdr[:16]))
|
||||||
@ -46,6 +45,7 @@ func FindExportData(r *bufio.Reader) (hdr string, err error) {
|
|||||||
// Read first line to make sure this is an object file.
|
// Read first line to make sure this is an object file.
|
||||||
line, err := r.ReadSlice('\n')
|
line, err := r.ReadSlice('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
err = fmt.Errorf("can't find export data (%v)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,13 +58,14 @@ func FindExportData(r *bufio.Reader) (hdr string, err error) {
|
|||||||
|
|
||||||
// First entry should be __.PKGDEF.
|
// First entry should be __.PKGDEF.
|
||||||
if name != "__.PKGDEF" {
|
if name != "__.PKGDEF" {
|
||||||
err = errors.New("go archive is missing __.PKGDEF")
|
err = fmt.Errorf("go archive is missing __.PKGDEF")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read first line of __.PKGDEF data, so that line
|
// Read first line of __.PKGDEF data, so that line
|
||||||
// is once again the first line of the input.
|
// is once again the first line of the input.
|
||||||
if line, err = r.ReadSlice('\n'); err != nil {
|
if line, err = r.ReadSlice('\n'); err != nil {
|
||||||
|
err = fmt.Errorf("can't find export data (%v)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,7 +73,7 @@ func FindExportData(r *bufio.Reader) (hdr string, err error) {
|
|||||||
// Now at __.PKGDEF in archive or still at beginning of file.
|
// Now at __.PKGDEF in archive or still at beginning of file.
|
||||||
// Either way, line should begin with "go object ".
|
// Either way, line should begin with "go object ".
|
||||||
if !strings.HasPrefix(string(line), "go object ") {
|
if !strings.HasPrefix(string(line), "go object ") {
|
||||||
err = errors.New("not a go object file")
|
err = fmt.Errorf("not a Go object file")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +81,7 @@ func FindExportData(r *bufio.Reader) (hdr string, err error) {
|
|||||||
// Begins after first line starting with $$.
|
// Begins after first line starting with $$.
|
||||||
for line[0] != '$' {
|
for line[0] != '$' {
|
||||||
if line, err = r.ReadSlice('\n'); err != nil {
|
if line, err = r.ReadSlice('\n'); err != nil {
|
||||||
|
err = fmt.Errorf("can't find export data (%v)", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user