It’s nearly midnight when I arrive via taxi from Glasgow-Prestwick Airport to a gatehouse in Ayr where I’ve booked a room with guaranteed late arrival.

I punch in the security code at the front door and step into a narrow hallway with a white loveseat and three sets of side tables I recognize from the latest Ikea catalogue.

After picking up lamps, books, and brochures and crawling on the floor underneath the tables in search of my key, it hits me. Reception’s forgotten their promise to leave me a room key. They don’t answer my calls or emails, either, so unless I want to sleep on the floor or a two-seater couch (I’m short, but not that short) I’ve got to figure something out, fast.

So it goes. Even the most carefully made travel plans will sometimes fail you.

So what do you do when—despite thorough planning—your reservation falls through or the room is too filthy or unsafe to stay in, and you’re stranded in a new place with nowhere to sleep off your jetlag?

Panic, of course. Once you’ve had your breakdown or hissy-fit (hopefully in the confines of your head without making too much noise and disturbing innocent passers-by) you’d better start problem-solving unless you want to sleep with one eye open at the bus station.

Here’s what you need to do.

photo-1428894976381-853e04af62621. Always communicate your arrival time with your accommodations. Make sure they (not the third-party booking site) confirm someone will be there to let you into a room, or can provide you with a passcode, and leave you a room key somewhere accessible. Although the example above proves this method is less than failsafe, it usually works just fine.

2. Contact a local. It doesn’t matter if it’s your brother’s ex-girlfriend’s sister’s college roommate. Locals will be able to advise you on the safety and convenience of specific neighborhoods, even if they’ve never stayed in a particular hotel. If the connection is strong enough and you’re staying for a long time, you could even ask your local contact to go check a place out in person. But be sure to share your priorities, and ask for pictures, if possible.

3. Only reserve a room at places with positive reviews. When you’ve never been somewhere, or even if you haven’t been for a few months or years, recent reviews from other guests help you choose the best accommodations before you get there. Focus on guests’ ratings of whatever’s most important to you—I’m neurotic about cleanliness and safety, but don’t care about noise. Everyone has their own priorities.

4. Keep taxi numbers handy. Have the number of a local registered taxi company in your wallet or phone so you can call a ride if you need to leave your accommodations for any reason. It’s a sure way to get a legit driver, and most drivers will even be able to recommend nearby hotels and hostels if yours hasn’t worked out and you haven’t been able to rebook yourself.

5. Carry the contact info for some other places to stay with you. Your second-choice and third-choices may be booked, but if they’re not, having the phone number could save you a frantic late night search for a hotel with positive guest reviews.

6. Bring your smartphone or tablet with data-roaming and international phone service enabled. If you’re lucky, you’ll have access to a phone or WIFI and you won’t have to use your data plan to find and rebook a place to stay. But enable data roaming anyway, even if you don’t plan to use it.

7. Contact the accommodations as soon as possible for a refund. Whether you were locked out and had to find somewhere else to stay, or have to back out on a reservation because the room is not as advertised, contact the accommodations right away to request a refund, if you’ve prepaid. If not, contact them to tell them why you won’t be paying and block payment.

8. Leave a review to help other travelers. Leaving negative reviews is no fun. But your advice could save someone else from having a similarly unpleasant experience. Don’t go overboard, though. Temper your criticisms with the truth and any positive feedback you’re able to provide.

Want more? Check out our ultimate guide to hotels!