MacOS – How to recover lost space after a bootcamp restore failed and APFS container failed to verify

bootcampmacospartitionwindows

I gave 50GB to bootcamp for Windows 10. Today, I decided I no longer want Windows 10 bootcamp. I went to bootcamp, and clicked restored. Then it said something about being unable to recover the partition space. I tried everything… I need help please. Thanks!

enter image description here
enter image description here
enter image description here

EDIT:
Running diskutil apfs resizeContainer disk0s2 0 gives the following:

Started APFS operation
Aligning grow delta to 48,684,773,376 bytes and targeting a new physical store size of 250,685,575,168 bytes
Determined the maximum size for the targeted physical store of this APFS Container to be 250,684,547,072 bytes
Resizing APFS Container designated by APFS Container Reference disk1
The specific APFS Physical Store being resized is disk0s2
Verifying storage system
Using live mode
Performing fsck_apfs -n -x -l -S /dev/disk0s2
Checking the container superblock
Checking the EFI jumpstart record
Checking the space manager
Checking the space manager free queue trees
Checking the object map
Checking volume
Checking the APFS volume superblock
The volume Macintosh HD was formatted by newfs_apfs (748.30.63) and last modified by apfs_kext (945.250.134)
Checking the object map
Checking the snapshot metadata tree
Checking the snapshot metadata
Checking the extent ref tree
Checking the fsroot tree
error: directory valence check: directory (oid 0x3c7efb): nchildren (1) does not match drec count (0) 
error: alloced_size (143360) of dstream (id 5451301) does not match calculated size (0)
error: alloced_size (143360) of dstream (id 5451301) does not match calculated size (0)
warning: apfs_num_files (2504403) is not valid (2504417)
warning: apfs_num_directories (909244) is not valid (909247)
Checking volume
Checking the APFS volume superblock
The volume Preboot was formatted by newfs_apfs (748.30.60) and last modified by apfs_kext (945.250.134)
Checking the object map
Checking the snapshot metadata tree
Checking the snapshot metadata
Checking the extent ref tree
Checking the fsroot tree
Checking volume
Checking the APFS volume superblock
The volume Recovery was formatted by newfs_apfs (748.30.60) and last modified by apfs_kext (945.250.134)
Checking the object map
Checking the snapshot metadata tree
Checking the snapshot metadata
Checking the extent ref tree
Checking the fsroot tree
Checking volume
Checking the APFS volume superblock
The volume VM was formatted by newfs_apfs (748.31.8) and last modified by apfs_kext (945.250.134)
Checking the object map
Checking the snapshot metadata tree
Checking the snapshot metadata
Checking the extent ref tree
Checking the fsroot tree
Verifying allocated space
Performing deferred repairs
error: found file extent gap (id 5451301) at logical address 0+143360
error: nchildren of inode object (id 3964667) does not match expected value
Deferred repairs failed
The volume /dev/disk0s2 could not be verified completely
Storage system check exit code is 8
Error: -69716: Storage system verify or repair failed

Best Answer

I reinstalled macOS. But it still didn't recover my 50GB.

So I went into disk utility, clicked on the 50GB chunk and after it was selected, I pressed delete on my keyboard and it recovered my 50GB back into the main partition.