# Code Smell 97 - Error Messages Without Empathy

*We should take special care with error descriptions for the users (and ourselves).*

> TL;DR: Use meaningful descriptions and suggest corrective actions.

# Problems

- The Least Surprise Principle

# Solutions

1. Use declarative error messages

2. Show clear exit actions

# Context

Programmers are seldom UX experts.

We also underestimate the fact we can be on both sides of the counter.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/e35210910d75821224dd75de8053b46f)
```javascript
alert("Cancel the appointment?", "Yes", "No");

//No consequences
//Options not clear
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/220e4c4d8eea96d15a0f34de2c5e96e3)
```javascript
alert("Cancel the appointment? \n" +
      "You will lose all the history", 
      "Cancel Appointment", 
      "Keep Editing");

//Consequences are clear
//Choice options have context
```

# Detection

[X] Manual

We need to read all exception messages in code reviews.

# Tags

- Exceptions

- UX

# Conclusion

We need to think in our end users when raising exception or showing messages.

# Credits

Photo by <a href="https://unsplash.com/@visuals">visuals</a> on <a href="https://unsplash.com/s/photos/error-message">Unsplash</a>
  

* * *

> While it is a known fact that programmers never make mistakes, it is still a good idea to humor the users by checking for errors at critical points in your program.

_Robert D. Schneider_ 
 
%[https://maximilianocontieri.com/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code]
