Handle GitHub file as not found
Fixes #345
diff --git a/gosrc/github.go b/gosrc/github.go
index 0de8968..4a37388 100644
--- a/gosrc/github.go
+++ b/gosrc/github.go
@@ -109,6 +109,13 @@
}
if _, err := c.getJSON(expand("https://api.github.com/repos/{owner}/{repo}/contents{dir}?ref={tag}", match), &contents); err != nil {
+ // The GitHub content API returns array values for directories
+ // and object values for files. If there's a type mismatch at
+ // the beginning of the response, then assume that the path is
+ // for a file.
+ if e, ok := err.(*json.UnmarshalTypeError); ok && e.Offset == 1 {
+ return nil, NotFoundError{Message: "Not a directory"}
+ }
return nil, err
}