Home / Learn Secure SQL / Reading Database Errors Safely

Reading Database Errors Safely

What an error message is allowed to tell you, and who.

The short versionWhat an error message is allowed to tell you, and who.

Theory in plain words

Two audiences, two messagesDeveloper, in logsFull error textFull queryStack traceEnd user, on screen"Something went wrong""Please try again"
Two audiences, two messages

The basic idea

Database error messages are extremely useful to a developer during development, and can be dangerous if shown, unfiltered, to an end user in production.

Why this comes up

An error message often contains the exact SQL that failed, table and column names, or even data. That is exactly the kind of detail that should stay internal.

The mechanics

In development, read the full error. In production, log the full error internally and show the user a short, generic message.

Where it is used

  • Web application code review
  • Backend development
  • Database administration

Try it

Reading a SQL error (expected error)SQL: edit and run

This fails on purpose because the column is misspelled. Read the error text the sandbox shows: it names the exact column. That is useful to you here, but should never reach a real end user screen.

Careful:Showing raw database errors to end users is covered in depth in the "Error handling, logging and monitoring" part of this course; this lesson is just the first mention.

Quick check

1. A raw database error is best shown to...