Add some error check

Add connection error handling
Add empty result checking if use stat command