diff options
author | Jeff Gaston <jeffrygaston@google.com> | 2017-08-23 17:30:05 -0700 |
---|---|---|
committer | Jeff Gaston <jeffrygaston@google.com> | 2017-09-01 17:29:30 -0700 |
commit | aca422058341fa613a735f2eaab76f5e15f05de7 (patch) | |
tree | 5d09faabc221557c5438b775f8e0ef3a77c3dfca /context.go | |
parent | 18a0d2e9b5d0c3f753e527da95e10779ed0f20fe (diff) | |
download | android_build_blueprint-aca422058341fa613a735f2eaab76f5e15f05de7.tar.gz android_build_blueprint-aca422058341fa613a735f2eaab76f5e15f05de7.tar.bz2 android_build_blueprint-aca422058341fa613a735f2eaab76f5e15f05de7.zip |
Clearer error in case of Android.bp being unreadable
Bug: 64600838
Test: mkdir errtest \
&& ln -s /tmp/dontexist errtest/Android.bp \
# and add errtest to ./Android.bp \
&& m nothing \
# and check that the error message mentions a symlink
Change-Id: I841ec12d613f61ccc3396538062bee48c8c1ca27
Diffstat (limited to 'context.go')
-rw-r--r-- | context.go | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -19,6 +19,7 @@ import ( "errors" "fmt" "io" + "os" "path/filepath" "reflect" "runtime" @@ -793,6 +794,23 @@ func (c *Context) parseBlueprintsFile(filename string, scope *parser.Scope, root f, err := c.fs.Open(filename) if err != nil { + // couldn't open the file; see if we can provide a clearer error than "could not open file" + stats, statErr := c.fs.Lstat(filename) + if statErr == nil { + isSymlink := stats.Mode()&os.ModeSymlink != 0 + if isSymlink { + err = fmt.Errorf("could not open symlink %v : %v", filename, err) + target, readlinkErr := os.Readlink(filename) + if readlinkErr == nil { + _, targetStatsErr := c.fs.Lstat(target) + if targetStatsErr != nil { + err = fmt.Errorf("could not open symlink %v; its target (%v) cannot be opened", filename, target) + } + } + } else { + err = fmt.Errorf("%v exists but could not be opened: %v", filename, err) + } + } errsCh <- []error{err} return } |