DEV Community

Cover image for Code Smell 166 - Low-Level Errors on User Interface
Maxi Contieri
Maxi Contieri

Posted on • Originally published at maximilianocontieri.com

2

Code Smell 166 - Low-Level Errors on User Interface

Fatal error: Uncaught Error: Class 'logs_queries_web' not found in /var/www/html/query-line.php:78 Stack trace: #0 {main} thrown in /var/www/html/query-line.php on line 718

TL;DR: Catch your errors. Even the ones you don't expect.

Problems

  • Security

  • Error Handling

  • Error Logging

  • Bad UX Experience

Solutions

  1. Use a top-level handler

  2. Avoid languages favoring return codes

  3. Expect database and low-level errors

Context

Even in 2022, we can see "serious" websites showing casual users a stack or debugging message.

Sample Code

Wrong


<?



Fatal error: Uncaught Error: Class 'MyClass' 

  not found in /nstest/src/Container.php:9

Enter fullscreen mode Exit fullscreen mode

Right


<?



// A user-defined exception handler function

function myException($exception) {

    logError($exception->description())

    // We don't show Exception to final users      

}



// Set user-defined exception handler function

set_exception_handler("myException");

Enter fullscreen mode Exit fullscreen mode

Detection

[X] Automatic

We can use mutation testing to simulate problems and see if they are handled correctly.

Tags

  • Security

Conclusion

We need to keep maturing.

Our solutions shouldn't be sloppy.

We need to improve our reputation as serious software engineers.

Relations

More Info

Disclaimer

Code Smells are just my opinion.

Credits

Photo by jesse orrico on Unsplash


80 percent of my problems are simple logic errors. 80 percent of the remaining problems are pointer errors. The remaining problems are hard.

Mark Donner


This article is part of the CodeSmell Series.

Tiugo image

Fast, Lean, and Fully Extensible

CKEditor 5 is built for developers who value flexibility and speed. Pick the features that matter, drop the ones that don’t and enjoy a high-performance WYSIWYG that fits into your workflow

Start now

Top comments (0)

Build gen AI apps that run anywhere with MongoDB Atlas

Build gen AI apps that run anywhere with MongoDB Atlas

MongoDB Atlas bundles vector search and a flexible document model so developers can build, scale, and run gen AI apps without juggling multiple databases. From LLM to semantic search, Atlas streamlines AI architecture. Start free today.

Start Free

👋 Kindness is contagious

Explore this insightful piece, celebrated by the caring DEV Community. Programmers from all walks of life are invited to contribute and expand our shared wisdom.

A simple "thank you" can make someone’s day—leave your kudos in the comments below!

On DEV, spreading knowledge paves the way and fortifies our camaraderie. Found this helpful? A brief note of appreciation to the author truly matters.

Let’s Go!