Skip to content

Commit 283e9cc

Browse files
AlexV525claude
andcommitted
Add [#1118]-tagged info logs to originFile path selection
Diagnosing this failure mode requires a way to tell PHImageManager and walker outputs apart on-device. Add three info-level log lines, all prefixed `[#1118]` so they can be filtered together: - `fetchOriginImageFile:` — one line per call recording the primary resource type, UTI, and whether the request will go through PHImageManager first or the walker first. Makes the routing decision visible without stepping through the code. - `fallbackFetchImageDataFor:` `dataHandler` — logs degraded intermediate drops (with byte count so a "large degraded" case is distinguishable from a "tiny thumbnail" one), cancellation, and the final delivered byte count with the destination path. - `writeImageResourceToFile:` — logs the delivered file size, resource UTI, and resource type on the walker's success path. Together, `grep [#1118]` on `xcrun devicectl log` (or Xcode Console) now yields a decision → delivery trail for every originFile call, so a reporter can attach the log excerpt when the returned bytes look smaller than expected — no debug build needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c0b5470 commit 283e9cc

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

  • darwin/photo_manager/Sources/photo_manager/core

darwin/photo_manager/Sources/photo_manager/core/PMManager.m

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,13 @@ - (void)fetchOriginImageFile:(PHAsset *)asset resultHandler:(PMResultHandler *)h
14421442
return;
14431443
}
14441444
[self notifyProgress:progressHandler progress:0 state:PMProgressStatePrepare];
1445+
PHAssetResource *primary = candidates.firstObject;
1446+
BOOL viaImageManager = [self canFetchOriginViaImageManager:primary];
1447+
[[PMLogUtils sharedInstance] info:[NSString stringWithFormat:
1448+
@"[#1118] fetchOriginImageFile id=%@ primary.type=%d uti=%@%@",
1449+
asset.localIdentifier, (int)primary.type,
1450+
primary.uniformTypeIdentifier ?: @"(nil)",
1451+
viaImageManager ? @"PHImageManager first" : @"walker first"]];
14451452
__weak typeof(self) weakSelf = self;
14461453
// Prefer PHImageManager.requestImageDataAndOrientation with
14471454
// deliveryMode=HighQualityFormat first: PHAssetResourceRequestOptions has
@@ -1496,7 +1503,7 @@ - (void)fetchOriginImageFile:(PHAsset *)asset resultHandler:(PMResultHandler *)h
14961503
}];
14971504
};
14981505

1499-
if (![self canFetchOriginViaImageManager:candidates.firstObject]) {
1506+
if (!viaImageManager) {
15001507
runWalker(nil);
15011508
return;
15021509
}
@@ -1597,6 +1604,12 @@ - (void)writeImageResourceToFile:(PHAssetResource *)imageResource
15971604
// Walker retries with the next candidate; don't emit Failed here.
15981605
block(nil, error);
15991606
} else {
1607+
long long size = [(NSNumber *)[[NSFileManager.defaultManager attributesOfItemAtPath:path error:nil]
1608+
objectForKey:NSFileSize] longLongValue];
1609+
[[PMLogUtils sharedInstance] info:[NSString stringWithFormat:
1610+
@"[#1118] writeDataForAssetResource delivered %lld bytes (uti=%@ type=%d) → %@",
1611+
size, imageResource.uniformTypeIdentifier ?: @"(nil)",
1612+
(int)imageResource.type, path]];
16001613
[strongSelf notifySuccess:progressHandler];
16011614
block(path, nil);
16021615
}
@@ -1650,9 +1663,13 @@ - (void)fallbackFetchImageDataFor:(PHAsset *)asset
16501663
// Ignore it and wait for the definitive callback — writing degraded
16511664
// bytes to disk would reproduce the very symptom of #1118.
16521665
if ([info[PHImageResultIsDegradedKey] boolValue]) {
1666+
[[PMLogUtils sharedInstance] info:[NSString stringWithFormat:
1667+
@"[#1118] PHImageManager degraded intermediate dropped, data=%lu",
1668+
(unsigned long)imageData.length]];
16531669
return;
16541670
}
16551671
if ([info[PHImageCancelledKey] boolValue]) {
1672+
[[PMLogUtils sharedInstance] info:@"[#1118] PHImageManager cancelled"];
16561673
block(nil, [NSError errorWithDomain:@"PMPhotoManager" code:-2 userInfo:@{
16571674
NSLocalizedDescriptionKey: @"PHImageManager request was cancelled."
16581675
}]);
@@ -1674,6 +1691,7 @@ - (void)fallbackFetchImageDataFor:(PHAsset *)asset
16741691
// originals (multi-MB HEIC/JPEG) can otherwise stall UI for tens of
16751692
// milliseconds while writing. Matches the pattern used by
16761693
// `fetchFullSizeImageFile:` below.
1694+
NSUInteger dataLength = imageData.length;
16771695
dispatch_async(strongSelf->_imageFileProcessingQueue, ^{
16781696
__strong typeof(weakSelf) innerSelf = weakSelf;
16791697
if (!innerSelf) { return; }
@@ -1683,6 +1701,9 @@ - (void)fallbackFetchImageDataFor:(PHAsset *)asset
16831701
block(nil, writeError);
16841702
return;
16851703
}
1704+
[[PMLogUtils sharedInstance] info:[NSString stringWithFormat:
1705+
@"[#1118] PHImageManager delivered %lu bytes → %@",
1706+
(unsigned long)dataLength, path]];
16861707
[innerSelf notifySuccess:progressHandler];
16871708
block(path, nil);
16881709
});

0 commit comments

Comments
 (0)