Don't use negative numbers for error codes


A warning to programmers - try to understand how people will use your error codes.

This morning, I was confronted with a rather bemusing error message on my WordPress blog: An error code with a negative number

Ok, so this should "never happen" and yet somehow it has. I wonder what on earth the error code means? I selected the error code and Googled it!

Google results for searching for an error code

I just copied and pasted the error message into Google and got back a set of meaningless results. Why?

Most search engines treat the minus sign as an "excludes" operator. Suppose I want to search for information about the Python programming language, but I don't want any results about snakes; Google lets me search for "python -snake".

In this case, Google is searching for every error code except for the one I want!

If we remove the - sign, the correct results are returned.

Google search for error code without a negative number - correct results returned

I've raised this as an issue with the software.

Remember, your error messages should be meaningful to the user. It should contain a clear explanation of what has happened and how the problem can be fixed. It should also be easy to search for information about the error. This message, sadly, fails at all three of those reasonable objectives.


Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

9 thoughts on “Don't use negative numbers for error codes”

    1. Terence Eden says:

      That's nice. How do you get Chrome, Opera, and Firefox to do that automatically? I just right clicked on the selected text and hit search.

      Reply
  1. says:

    I use quotes too: error code "-32300"

    Quotes can also be used to force Google (I assume that's who we're talking about?!) to return links that actually include the search term (which they sometimes don't - indicated by the term with a strikethrough through it as part of a result listing)

    Reply
    1. Terence Eden says:

      Will most users understand how to do that? The default when you select text is to not use quotes. Should we try to get users to change their habits - or make minor changes which make their life easier?

      Reply
  2. As Alex B said, you just put the error code, or the whole error in quotes and it'll be fine. Try searching:

    Error code: "-32000"

    If there was an issue with negative numbers, we'd have a general problem, since how would you google things like "why is e^(i pi) equal to -1" or any other searches related to negative numbers.

    Just use quotes

    Reply
    1. Terence Eden says:

      What are the advantages of using a negative number as an error code?

      Reply

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">