Nexus 5 failed recovery due to /data partition I got a nexus 5 off of eBay, the seller said he had tried to root it and failed so I thought I would have a crack at it.
I thought it would be an easy restore but I ran into a few problems:

Phone originally came with 6.0.1 installed.
On android 5+ I could not access the standard recovery screen, and when I pressed power+volUp it just said formatting /data and would not move from that.

Rolled back to 4.4 and I got into the ususal recovery screen. 
Tried to do a factory reset, but it again stuck at formatting /data.
I left it the entire night while I slept and it was still saying formatting /data. in the morning, nothing had changed.
Trying to boot the phone normally just left it on the 4 circles startup screen.

I've tried doing a full flash of stock android with each seperate part manually.
Also /data is unable to be mounted in any custom recovery, like it is corrupted or locked somehow.
With the stock recovery, it cannot be detected by adb, but in cwm it can. However, it still doesn't allow access to /data.

Checking the /data folder in adb shell shows it's completely empty, and the same with system even after flashing and flashing again.

Can anyone advise me as to what might be the problem here?
I used this link to repair my /data directory:

http://forum.xda-developers.com/google-nexus-5/general/howto-repairing-corrupted-data-partition-t2577447

Fortunately I was able to boot into fastboot mode the usual way ( Volume down and power at the same time ) unfortunately TWRP kept looping after erring on the corrupted /data folder. I ended up replacing TWRP with "Philz Recovery Nexus 5" because it booted up normally. I then formatted the /data, /system, /cache directories. That fixed the /data directory error and corruption problem. I was able to load CM13 successfully after that. I had to use a OTG external USB drive to load Philz Recovery Nexus 5, CM13 and GApps. I hope this helps. I'm sticking with Philz Recovery Nexus 5. It fixed the problem!