DEV Community

Cover image for Code Smell 97 - Error Messages Without Empathy
Maxi Contieri
Maxi Contieri

Posted on • Originally published at maximilianocontieri.com

5 1

Code Smell 97 - Error Messages Without Empathy

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

TL;DR: Use meaningfull 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

alert("Cancel the appointment?", "Yes", "No");

//No consequences
//Options not clear
Enter fullscreen mode Exit fullscreen mode

Right

alert("Cancel the appointment? \n" +
      "You will lose all the history", 
      "Cancel Appointment", 
      "Keep Editing");

//Consequences are clear
//Choice options have context
Enter fullscreen mode Exit fullscreen mode

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 visuals on Unsplash


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


This article is part of the CodeSmell Series.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay