If someone wrote a PowerShell program, with multiple lines and without caring the coding standard and you got stuck to find where the error is, so very simplest way which I am thinking is just use below piece of code which saves your time and let you know about a line which is having an issue.
InvocationInfo can provide information about how and where this command was invoked
So just use simple try-catch like below
try { #<replace with your code> } catch { $_ |select -expandproperty invocationinfo write-host "$($_.Exception.Message)" -foregroundcolor red break; }