[covargs] Skip invalid profile files

Some profile files may be corrupted, filter those out to avoid
llvm-profdata merge failures.

Change-Id: I408f29e506b9a3ba292f5c205001bc23e4c7bb62
diff --git a/cmd/covargs/main.go b/cmd/covargs/main.go
index fc3aa76..0e4b88b 100644
--- a/cmd/covargs/main.go
+++ b/cmd/covargs/main.go
@@ -264,6 +264,17 @@
 				modSet[mod] = struct{}{}
 			}
 		}
+		// TODO(https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=34796): ideally this would
+		// be handled by llvm-profdata tool itself.
+		cmd := exec.Command(llvmProfdata, "show", entry.ProfileData)
+		if err := cmd.Run(); err != nil {
+			if _, ok := err.(*exec.ExitError); ok {
+				fmt.Fprintf(os.Stderr, "WARN: %q profile is corrupted\n", entry.ProfileData)
+				continue
+			} else {
+				return fmt.Errorf("llvm-profdata show %s failed: %v", entry.ProfileData, err)
+			}
+		}
 		covFiles = append(covFiles, entry.ProfileData)
 	}