Skip to content

Commit 519b965

Browse files
committed
Fixed #33: xml parsing errors were returned from lookups
1 parent fa85cce commit 519b965

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

vcs_remote_lookup.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ func detectVcsFromRemote(vcsURL string) (Type, string, error) {
9090
return t, vcsURL, nil
9191
}
9292

93-
// Need to test for vanity or paths like golang.org/x/
94-
95-
// TODO: Test for 3xx redirect codes and handle appropriately.
96-
9793
// Pages like https://golang.org/x/net provide an html document with
9894
// meta tags containing a location to work with. The go tool uses
9995
// a meta tag with the name go-import which is what we use here.
@@ -117,10 +113,14 @@ func detectVcsFromRemote(vcsURL string) (Type, string, error) {
117113
return NoVCS, "", ErrCannotDetectVCS
118114
}
119115
defer resp.Body.Close()
116+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
117+
return NoVCS, "", ErrCannotDetectVCS
118+
}
120119

121120
t, nu, err := parseImportFromBody(u, resp.Body)
122121
if err != nil {
123-
return NoVCS, "", err
122+
// TODO(mattfarina): Log the parsing error
123+
return NoVCS, "", ErrCannotDetectVCS
124124
} else if t == "" || nu == "" {
125125
return NoVCS, "", ErrCannotDetectVCS
126126
}
@@ -299,6 +299,7 @@ func get(url string) ([]byte, error) {
299299
}
300300
defer resp.Body.Close()
301301
if resp.StatusCode != 200 {
302+
// TODO(mattfarina): log the failed status
302303
return nil, fmt.Errorf("%s: %s", url, resp.Status)
303304
}
304305
b, err := ioutil.ReadAll(resp.Body)

vcs_remote_lookup_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ func TestVCSLookup(t *testing.T) {
1313
"https://github.com/masterminds": {work: false, t: Git},
1414
"https://github.com/Masterminds/VCSTestRepo": {work: true, t: Git},
1515
"https://bitbucket.org/mattfarina/testhgrepo": {work: true, t: Hg},
16+
"https://bitbucket.org/mattfarina/repo-does-not-exist": {work: false, t: Hg},
17+
"https://bitbucket.org/mattfarina/private-repo-for-vcs-testing": {work: false, t: Hg},
1618
"https://launchpad.net/govcstestbzrrepo/trunk": {work: true, t: Bzr},
1719
"https://launchpad.net/~mattfarina/+junk/mygovcstestbzrrepo": {work: true, t: Bzr},
1820
"https://launchpad.net/~mattfarina/+junk/mygovcstestbzrrepo/trunk": {work: true, t: Bzr},
@@ -56,6 +58,10 @@ func TestVCSLookup(t *testing.T) {
5658
t.Errorf("Error detecting VCS from URL(%s): %s", u, err)
5759
}
5860

61+
if err != nil && err != ErrCannotDetectVCS && c.work == false {
62+
t.Errorf("Unexpected error returned (%s): %s", u, err)
63+
}
64+
5965
if c.work == true && ty != c.t {
6066
t.Errorf("Incorrect VCS type returned(%s)", u)
6167
}

0 commit comments

Comments
 (0)