And it fails becouse, when you use goto then the script is looking for goto points (:error and :end in your case) in every if statement and you have two of :error. If you don't use goto, then only one :error point is seen, becouse the second if statement is not looked, becouse it is not true.