Bug 1306033 - Only fatal console warnings on failures of OpenAlternativeInputStream in HTTP cache. r=michal
authorHonza Bambas <honzab.moz@firemni.cz>
Thu, 29 Sep 2016 07:26:00 -0400
changeset 419825 06cb6118fd79e14fa3e2573cdfad025b12d7eae6
parent 419824 b577f6e25606543a4161c3a589bd288e0051ce02
child 419826 95c7a910a0794052472a111ab45a4ff8d0111925
push id31023
push usercykesiopka.bmo@gmail.com
push dateSat, 01 Oct 2016 01:30:33 +0000
reviewersmichal
bugs1306033
milestone52.0a1
Bug 1306033 - Only fatal console warnings on failures of OpenAlternativeInputStream in HTTP cache. r=michal
netwerk/cache2/CacheEntry.cpp
netwerk/cache2/CacheFile.cpp
--- a/netwerk/cache2/CacheEntry.cpp
+++ b/netwerk/cache2/CacheEntry.cpp
@@ -1147,20 +1147,26 @@ nsresult CacheEntry::OpenInputStreamInte
   nsresult rv;
 
   RefPtr<CacheEntryHandle> selfHandle = NewHandle();
 
   nsCOMPtr<nsIInputStream> stream;
   if (aAltDataType) {
     rv = mFile->OpenAlternativeInputStream(selfHandle, aAltDataType,
                                            getter_AddRefs(stream));
+    if (NS_FAILED(rv)) {
+      // Failure of this method may be legal when the alternative data requested
+      // is not avaialble or of a different type.  Console error logs are ensured
+      // by CacheFile::OpenAlternativeInputStream.
+      return rv;
+    }
   } else {
     rv = mFile->OpenInputStream(selfHandle, getter_AddRefs(stream));
+    NS_ENSURE_SUCCESS(rv, rv);
   }
-  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISeekableStream> seekable =
     do_QueryInterface(stream, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, offset);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/netwerk/cache2/CacheFile.cpp
+++ b/netwerk/cache2/CacheFile.cpp
@@ -778,17 +778,17 @@ CacheFile::OpenAlternativeInputStream(ns
                                       nsIInputStream **_retval)
 {
   CacheFileAutoLock lock(this);
 
   MOZ_ASSERT(mHandle || mMemoryOnly || mOpeningFile);
 
   nsresult rv;
 
-  if (!mReady) {
+  if (NS_WARN_IF(!mReady)) {
     LOG(("CacheFile::OpenAlternativeInputStream() - CacheFile is not ready "
          "[this=%p]", this));
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   if (mAltDataOffset == -1) {
     LOG(("CacheFile::OpenAlternativeInputStream() - Alternative data is not "
          "available [this=%p]", this));
@@ -805,27 +805,27 @@ CacheFile::OpenAlternativeInputStream(ns
     // it's also doomed, so reopening the entry won't make any difference -
     // data will still be inaccessible anymore.  Note that for just doomed 
     // files, we must allow reading the data.
     return mStatus;
   }
 
   const char *altData = mMetadata->GetElement(CacheFileUtils::kAltDataKey);
   MOZ_ASSERT(altData, "alt-metadata should exist but was not found!");
-  if (!altData) {
+  if (NS_WARN_IF(!altData)) {
     LOG(("CacheFile::OpenAlternativeInputStream() - alt-metadata not found but "
          "alt-data exists according to mAltDataOffset! [this=%p, ]", this));
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   int64_t offset;
   nsCString availableAltData;
   rv = CacheFileUtils::ParseAlternativeDataInfo(altData, &offset,
                                                 &availableAltData);
-  if (NS_FAILED(rv)) {
+  if (NS_WARN_IF(NS_FAILED(rv))) {
     MOZ_ASSERT(false, "alt-metadata unexpectedly failed to parse");
     LOG(("CacheFile::OpenAlternativeInputStream() - Cannot parse alternative "
          "metadata! [this=%p]", this));
     return rv;
   }
 
   if (availableAltData != aAltDataType) {
     LOG(("CacheFile::OpenAlternativeInputStream() - Alternative data is of a "