[upload_debug_symbols] Validate .debug files before attempting upload

Currently, we have logic to validate debug files in two places:
one while attempting to upload, and one before upload. This change
consolidates these checks into one place before upload attempt for
better separation of concerns (errors during upload should only
report upload-related errors).

Additionally, we will log warnings instead of failures when running
bfr.Verify, such that the tool can walk higher-level directories
without requiring upfront that all .debug files within are valid
for the tool.

Change-Id: Ib6ed4fa9f5a972b987e98db997035d1a425f9b52
diff --git a/cmd/upload_debug_symbols/job.go b/cmd/upload_debug_symbols/job.go
index b6b9b68..4656d6d 100644
--- a/cmd/upload_debug_symbols/job.go
+++ b/cmd/upload_debug_symbols/job.go
@@ -50,9 +50,6 @@
 }
 
 func (j *job) execute(ctx context.Context, bkt *GCSBucket) error {
-	if err := j.bfr.Verify(); err != nil {
-		return fmt.Errorf("validation failed for %q: %v", j.bfr.Filepath, err)
-	}
 	object := j.bfr.BuildID + elflib.DebugFileSuffix
 	filepath := j.bfr.Filepath
 	reader, err := os.Open(filepath)
diff --git a/cmd/upload_debug_symbols/main.go b/cmd/upload_debug_symbols/main.go
index df0ed41..a3cc342 100644
--- a/cmd/upload_debug_symbols/main.go
+++ b/cmd/upload_debug_symbols/main.go
@@ -78,7 +78,7 @@
 	if err != nil {
 		return fmt.Errorf("failed to collect symbol files: %v", err)
 	}
-	bfrs = filterEmptyDebugSymbolFiles(bfrs)
+	bfrs = filterInvalidDebugSymbolFiles(bfrs)
 	jobs, err := queueJobs(bfrs)
 	if err != nil {
 		return fmt.Errorf("failed to queue jobs: %v", err)
@@ -100,8 +100,8 @@
 	return nil
 }
 
-// Returns filtered input of BinaryFileRefs, skipping files without .debug_info header.
-func filterEmptyDebugSymbolFiles(bfrs []elflib.BinaryFileRef) []elflib.BinaryFileRef {
+// Returns filtered input of BinaryFileRefs, skipping files without .debug_info header or valid build ID.
+func filterInvalidDebugSymbolFiles(bfrs []elflib.BinaryFileRef) []elflib.BinaryFileRef {
 	var filteredBfrs []elflib.BinaryFileRef
 	for _, bfr := range bfrs {
 		hasDebugInfo, err := bfr.HasDebugInfo()
@@ -109,6 +109,8 @@
 			log.Printf("WARNING: cannot read file %s: %v, skipping\n", bfr.Filepath, err)
 		} else if !hasDebugInfo {
 			log.Printf("WARNING: file %s missing .debug_info section, skipping\n", bfr.Filepath)
+		} else if err := bfr.Verify(); err != nil {
+			log.Printf("WARNING: validation failed for %s: %v, skipping\n", bfr.Filepath, err)
 		} else {
 			filteredBfrs = append(filteredBfrs, bfr)
 		}