# Shortest Error Message

Challenge

Write the shortest program that, when compiled or executed, produces a fatal error message smaller than the program itself. The error message may not be generated by the program itself, such as Python's raise. A valid answer must include both the code and the error message. Shortest valid answer wins.

No error message does not count as an error message.

Example (Lua)

Code (46 bytes):

[
--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa


Error (45 bytes):

[string "[..."]:1: unexpected symbol near '['

• Comments are not for extended discussion; this conversation has been moved to chat. Jul 28, 2017 at 16:18
• @Dennis I guess that's one way of solving the "OP doesn't edit clarifications into question" problem. Jul 29, 2017 at 23:52
• Thanks for accepting my answer, which got the most votes; however, this was tagged code-golf, so you should accept this answer, which is the shortest. Nov 24, 2017 at 21:38
• @smartpeople is this: "__main__.CodeException: Raised an &rror." my error or is this:"Raised an &rror." Dec 25, 2017 at 17:13
• TrumpScript running in China? Jan 30, 2018 at 6:34

# ed, 3 bytes

Note: Most of the answers here are ignoring the trailing newline printed as part of the error message in their count. But I don’t see anything in the question to justify ignoring it, and the author commented that the newline should be included. So unless the question is changed, I’m going to include it.

Code (with trailing newline):

??



Error (with trailing newline):

?


• Actually, this is impossible to beat. :P Jul 21, 2017 at 20:21
• Can ed do addition and primality testing? Or is that not required for this type of challenge? Jul 21, 2017 at 22:34
• @StepHen Yes, it can do addition and primality testing in unary via the usual regex-with-backreferences trick. Jul 22, 2017 at 0:57
• Very clever, but '?' isn't fatal. Jul 27, 2017 at 11:50
• As pointed out in a flag, the error is fatal if the code isn't read from a terminal. Try it online! Jul 4, 2018 at 14:12

# C (modern Linux), 19 bytes

Would've done my famous segfault but totallyhuman stole it.

main(){longjmp(0);}


Output (18 bytes):

Segmentation fault

• You currently have a higher score than me so... Win-win? Jul 21, 2017 at 20:23
• Jul 21, 2017 at 21:48
• Are there no other locale with a shorter version (So that you could then use main(){main();})? Jul 27, 2017 at 13:10
• @12431234123412341234123 Not that I know of. Also, main(){main();} is not guaranteed to seg-fault. Jul 30, 2017 at 20:51
• @MDXF There is no guarantee (and with optimization enabled in gcc or clang, it end up in a endless loop or ignore the call). But on Code Golf we need a working implementation not a guarantee. Jul 31, 2017 at 9:08

# Python 2, 35 bytes

import sys;sys.tracebacklimit=000;a


Gives error:

NameError: name 'a' is not defined

• modifying the traceback limit... nice one Jul 21, 2017 at 19:44
• This is clever! Jul 24, 2017 at 19:37

## JavaScript (Firefox), 31 bytes

# This is a comment, right? ...


Throws this error:

SyntaxError: illegal character


Tested in the console of Firefox 54.0.1 on Windows 7.

# Python 2, 87 79 bytes

-8 bytes thanks to Zacharý and Erik the Outgolfer.

from __future__ import braces
#i am most surely seriously actually totallyhuman


Try it online!

## Error message, 78 bytes:

Assuming the code is stored in a file named a.

  File "a", line 1
from __future__ import braces
SyntaxError: not a chance


This is actually a nice little Easter egg in Python. :D

• You can assume a one-char file name! Jul 21, 2017 at 19:28
• Assuming a 1-char file name, you can golf to this. Jul 21, 2017 at 19:36
• Heh, nice. - - - Jul 21, 2017 at 19:40
• But the error message has to be smaller than the program itself... Jul 21, 2017 at 20:06
• If you use IDLE you can get \s\sFile "<stdin>", line 1\nSyntaxError: not a chance which is only 50 bytes [\s is a space and \n is a newline], so you can get a 51 byte program.. Jul 26, 2017 at 8:39

main = (main)


Save as t.hs or another one-character name, compile with ghc, and run. Error message (with trailing newline):

t: <<loop>>


# ><>, 26 bytes

>>>>>>>>>>>>>>>>>>>>>>>>>:


Try it online!

Every error message in Fish is something smells fishy..., so this just moves the pointer right enough times to be longer than that and attempts to duplicate the top of the stack, which is empty at the time.

• I like it, and it's definately the most fishy of all solutions :-) Jul 25, 2017 at 16:58
• @Xan-KunClark-Davis sigh you had to... :P Jul 25, 2017 at 17:26

# Taxi, 38 21 bytes

Switch to plan "abc".


Produces:

error: no such label


Try it online!

-17 bytes thanks to Engineer Toast

Tries to switch to "abc", which does not exist. You would have [abc] somewhere.

• You can get down to 21 bytes with Switch to plan "abc". producing error: no such label. This might be one of the few code-golf challenges where Taxi beats some traditional languages. Jul 21, 2017 at 20:00
• @EngineerToast thanks, didn't think of that one. Jul 21, 2017 at 20:03

## JavaScript (Firefox), 21 bytes

(a=null)=>a.charAt(1)


Error (20 bytes): TypeError: a is null

• D'oh! I knew there was a shorter one... Jul 21, 2017 at 20:49
• I had the same idea, came up with a=null;a.x01234567890 Same amount of bytes Nov 9, 2017 at 13:43

# System V shell, 25 bytes

mount /dev/hda1 /mnt/hda1


Error message (23 bytes):

mount: not a typewriter


"Not a typewriter" or ENOTTY is an error code defined in errno.h on Unix systems. This is used to indicate that an invalid ioctl (input/output control) number was specified in an ioctl system call. On my system, in /usr/include/asm-generic/errno-base.h, I can find this line:

#define ENOTTY          25      /* Not a typewriter */


In Version 6 UNIX and older, I/O was limited to serial-connected terminal devices, such as a teletype (TTY). These were usually managed through the gtty and stty system calls. If one were to try to use either of these system calls on a non-terminal device, ENOTTY was generated.

Nowadays, there is naturally no need to use a teletype. When gtty and stty were replaced with ioctl, ENOTTY was kept. Some systems still display this message; but most say "inappropriate ioctl for device" instead.

• Please explain... Jul 22, 2017 at 17:05
• @MegaMan Updated with explanation. Jul 22, 2017 at 17:46
• Upvote for actually enlightening explanation. Jul 25, 2017 at 17:00

# TrumpScript, 30 bytes

We love NATO!
America is great


Error message:

Trump doesn't want to hear it

• P.S. Error codes are in constants.py Jul 26, 2017 at 12:52

# QBasic, 11 bytes

There are two solutions of 11 bytes in QBasic, one of which might be golfed further. The shortest error message QBasic has is overflow, and can be triggered as such:

i%=i%+32677


This throws overflow because the max for an integer (i%) is 32676. I couldn't get the 32677 golfed without QBasic auto-casting this to long...

Another error, at 11 bytes, would be out of data. QBasic has DATA statements that store data in the program, which can later be accessed by READ statements. Issuing more READs than DATAs causes the error:

READ a$'--  Note that the statement is padded with a comment to get it up to the length of the error message. Yes, I have an error message with a shorter program, and a program with a shorter error message ... # Javascript (V8), 24 bytes decodeURIComponent('%');  Error, 23 bytes: URIError: URI malformed  Tested on Nodejs v6.11.0 and Google Chrome v59.0.3071.115. Try it online! Note that TIO expands the error message. • Welcome to PPCG! Jul 24, 2017 at 13:02 # C (Modern Linux), 19 bytes I suggested this in chat, but nobody took the oppurtunity. :P Credit to MD XF's hilarious answer. main(){puts('s');;}  ## Error message, 18 bytes Segmentation fault  • But the error message has to be smaller than the program itself... Jul 21, 2017 at 20:08 • Byte counts were screwed up, my bad. Jul 21, 2017 at 20:16 • This is a generic message printed by the shell when subprocess terminates with exit code 139. The C program itself produces no error message at all. Jul 21, 2017 at 21:41 • @Dennis Exit code 139 is actually another lie made up by the shell. Unix distinguishes between signal 11 (W_EXITCODE(0, 11) == 11) and exit code 139 (W_EXITCODE(139, 9) == 139 << 8). Shells set $? non-surjectively to WIFEXITED(wstatus) ? WEXITSTATUS(wstatus) : WTERMSIG(wstatus) + 128, but most languages expose the difference. Jul 22, 2017 at 18:05
• @Anders Is WIFEXITED(wstatus) equivalent to DIVORCE(alimony) by any chance? Jul 27, 2017 at 10:50

## Commodore 64 Basic, 15 bytes

?SYNTAX   ERROR


Produces

?SYNTAX  ERROR


(Note two spaces in the error message, where the program has three)

?SYNTAX ERROR is tied with ?VERIFY ERROR as the third-shortest error message that C64 Basic can produce, and the shortest that can be reliably triggered by code (the shortest message, BREAK IN 1, requires user interaction, while ?LOAD ERROR requires a defective tape or floppy disk, and ?VERIFY ERROR requires the presence of a floppy or tape containing a file that doesn't match the program in RAM).

• Ha, didn't even see this when I posted mine. Always good to see another BASIC user... +1 Jul 23, 2017 at 0:51

# PowerShell, 215 189 bytes

[]
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111


Try it online!

So, PowerShell has ... verbose ... error messages. Additionally, most non-syntax error messages are Runtime Exceptions, meaning that they're non-fatal, which reduces this problem to needing to find a short parsing error.

I think this is one of the shortest, if not the shortest, @TessellatingHeckler has demonstrated this is the shortest parsing error, and it still weighs in at 188 bytes just for the error message. So we basically need to append enough 1s to reach 189 bytes of "code."

Running this locally on c:\a.ps1 for example, will cut down on the byte count by a handful as it's just a shorter file path, but then it's not available on TIO.

Produces error:

At /tmp/home/.code.tio.ps1:1 char:2
+ []
+  ~
Missing type name after '['.
+ CategoryInfo          : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingTypename

• @user72528 Yeah, I found that amusing as well. Jul 21, 2017 at 19:38
• You can use a one char file name! Jul 21, 2017 at 19:54
• @Zacharý I can, but then it's not reproducible on TIO due to how TIO handles the sandboxing. I prefer to keep it usable on TIO than to save a few bytes. Jul 21, 2017 at 20:00
• What about [] which looks like a shorter error Missing type name after '[' and depending on exactly how you count could be around 190 - tio.run/##K8gvTy0qzkjNyfn/PzqWy3Dogv//AQ (taken from the parser strings here that looks like the shortest parser error to me ([xml](gc .\ParserStrings.resx)).root.data.value | sort { $_.length } -Desc). Jul 21, 2017 at 21:34 # Vyxal, 309 bytes In this answer, I coded it so that the program errors when executed․ Also, according to code-golf statistics, only a small percentage of people who view my answers actually upvote․ So if you enjoy this answer, please consider upvoting - it's free, and you can change your mind at any time․ Enjoy the answer․  I request that you imagine Epic Dawn by Bobby Cole is playing while reading this answer. ## The Error Traceback (most recent call last): File "C:\Users\61419\Desktop\Vyxal\Vyxal.py", line 867, in <module> exec(line) File "<string>", line 4, in <module> File "C:\Users\61419\Desktop\Vyxal\Vyxal.py", line 592, in VY_int return int(item, base) ValueError: invalid literal for int() with base 10: ''  # Explained This fails immediately on the first instruction it sees: I. It tries to convert the empty input to base 10 (which is impossible) • PPCG: YouTube edition. 😂 Jan 5, 2021 at 14:20 • -308 bytes (2.4.1 online only) Dec 9, 2021 at 9:56 # Ruby (33 32 bytes) 32 bytes & #abcdefghijklmnopqrstuvwxyz12  Throws the error (assuming in a file named "a"): 31 bytes a:1: syntax error, unexpected &  Edit: Shaved a byte off by using & instead of << thanks to Eric, who also came up with an even shorter Ruby solution: http://codegolf.stackexchange.com/a/135087/65905 • Welcome to PPCG! Jul 21, 2017 at 19:56 • @EricDuminil nice! I thought all the single character operators were quoted in the error message, but you're right: & isn't. Neat! Also, good find with the hex escape. I was struggling to find a shorter and non-stack-trace fatal error message other than a syntax error. Jul 23, 2017 at 19:53 • @ameketa: I actually wrote a bruteforce program and tested every possible 1, 2 and 3-byte Ruby program :D Thanks for the link. Jul 23, 2017 at 20:50 # R, 29 28 bytes -1 byte thanks to JarkoDubbeldam a #abcdefghijklmnopqrstuvwxy  Throws the error Error: object 'a' not foundwhich is 27 bytes. Try it online! • a #abcdefghijklmnopqrstuvwxy's error Error: object 'a' not found is one byte shorter. – JAD Jul 23, 2017 at 15:16 • @JarkoDubbeldam thank you. Jul 25, 2017 at 17:45 # Brainf**k, 17 bytes, this interpreter +++++++++++++++<<  Brainf**k is such a simple language that almost every interpreter has a different error message. This one uses Memory Error: -1 for when the pointer is moved to the left too much and you attempt another operation • I guess choosing an interpreter is as much a part of the challenge as choosing a language. Jul 21, 2017 at 19:18 • @user72528 Well here, we define a language by its interpreter, so this challenge is a bit about choosing the interpreter with the shortest error messages :) Jul 21, 2017 at 19:21 • Who beats brainfuck? Nobody? Alright. Jul 21, 2017 at 19:28 • The unbeatable solution would a two byte solution which causes an error of 1 character. Jul 21, 2017 at 19:30 • @Zacharý Certainly lol Jul 21, 2017 at 19:44 # Common Lisp, 20 bytes (/ 1 0))))))))))))))  Try it online! Error Message /: division by zero  • o_o unbalanced parentheses in Lisp ... you learn something new every day. Jul 21, 2017 at 19:32 • If you replace the 0 with 1, it will error on the parens but it doesn't get that far with 0. I just needed to add characters to be longer than the message Jul 21, 2017 at 19:34 # TryAPL, 11 bytes Code (11): 'abcdefghij  Error (10): open quote  # ZX Spectrum Basic, 9 bytes RUN USR 8  produces: Explanation: I am (exceptionally) counting ASCII representation of the program for length purposes, including the end of line (it's not really important, since we could always pad a shorter program with spaces). Usually, ZX Spectrum error messages are longer and more helpful than this - the ROM routine at 0x0008 expects error code following the machine code call to RST 8., and fetches some random (deterministic) byte from the ROM, which produces this nonsensical error message M. 5 is the error number, , is added by the error printing routine and 0:1 is the line:command position of the error. • Actually this is 9 bytes normally anyway, because the ZX Spectrum doesn't evaluate numbers at run time, so there are actually 6 hidden bytes which allow it to access the binary representation of 8 directly. – Neil Jul 23, 2017 at 19:11 # ArnoldC, 150 bytes IT'S SHOWTIME HEY CHRISTMAS TREE b YOU SET US UP 0 GET TO THE CHOPPER b HERE IS MY INVITATION b HE HAD TO SPLIT 0 ENOUGH TALK YOU HAVE BEEN TERMINATED  Try it online! Error is 94 bytes (including trailing newline): Exception in thread "main" java.lang.ArithmeticException: / by zero at code.main(Hello.java)  Preserved because I think this is more funny - spoiler: it was those dang teenage pranksters. # ArnoldC, 280 bytes IT'S SHOWTIME HEY CHRISTMAS TREE BRBDoorBetterNotBeThosePeskyTeenagePranksters YOU SET US UP 0 GET YOUR ASS TO MARS BRBDoorBetterNotBeThosePeskyTeenagePranksters DO IT NOW I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY YOU HAVE BEEN TERMINATED  Pseudocode: start program new variable set to 0 set new variable to output from function call function take input end program  Try it online! Generates a "no input" error. (Almost all other errors in ArnoldC include a large piece of boilerplate): 279 bytes (including trailing newline): Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at code.main(Hello.java)  # Perl 5, 5 bytes die$/


Outputs a newline, for one byte.

Try it online!

• ._. Now ... if only perl errors on the empty file! Jul 22, 2017 at 1:34
• Wait, is this a violation of the "may not be generated by the program itself"? I didn't understand what that rule was saying. Jul 22, 2017 at 1:41
• @Zacharý ... giving an error message with total length negative one? Jul 22, 2017 at 1:54
• This might be invalid ... or not, depends on whether the OP meant the error or the error message Jul 22, 2017 at 2:14
• ^ clarification: whether a program errors directly or creates an error message directly Jul 23, 2017 at 0:31

# Javascript(Firefox),29 27 bytes

new Date('-').toISOString()


throws RangeError: invalid date which is 24 bytes. Tested on Firefox 54.0.1 on Windows 10.

# Perl 5, 11 bytes

Since I'm not clear on whether my other answer obeys the challenge rules, here's another alternative.

#line 0
die


Error output:

Died.


With an ending newline, for 6 bytes.

Try it online!

For some reason the Perl interpreter internal function Perl_mess_sv contains:

if (CopLINE(cop))
Perl_sv_catpvf(aTHX_ sv, " at %s line %" IVdf,
OutCopFILE(cop), (IV)CopLINE(cop));


where CopLINE(cop) gets the current code context's line number. So if that line number happens to evaluate to zero, Perl skips adding the usual " at <filename> line <n>" to the error message.

• It seems nor valid to me. IIRC die is for the program to exit. Jul 22, 2017 at 17:34
• How is that any different than python raise? Jul 23, 2017 at 12:09
• Well, the OP might have been referring to either generating the error or the error message. I commented on which one he meant. Jul 23, 2017 at 14:42

# Whitespace (on TIO), 34 bytes


Nope, it's not valid Whitespace!

Try it online.

All characters that aren't a space, tab, or newline are ignore in Whitespace. So this program is actually SNSSS (where S is space, and N is newline). The first three (SNS) is the command to duplicate the value at the top of the stack. Since the stack is still empty, it gives the error:

wspace: user error (Can't do Dup)


I tried other errors, but this seems to be the shortest. Most errors where it tries to use a value on the stack which isn't present are similar, but longer. Here is a list of all possible errors (I could find) on TIO (for the first one it requires a character input, which it tries to read and print as number, so I've excluded that one - Try it online.):

wspace: Prelude.read: no parse
wspace: user error (Can't do Dup)
wspace: user error (Can't do Swap)
wspace: Prelude.!!: index too large
wspace: user error (Can't do Store)
wspace: user error (Can't do Return)
wspace: user error (Can't do Discard)
wspace: user error (Can't do Slide 0)
wspace: user error (Can't do ReadNum)
wspace: user error (Can't do Retrieve)
wspace: user error (Can't do ReadChar)
wspace: <stdin>: hGetChar: end of file
wspace: <stdin>: hGetLine: end of file
wspace: user error (Can't do OutputNum)
wspace: user error (Can't do Infix Plus)
wspace: user error (Can't do OutputChar)
wspace: user error (Undefined label ( ))
wspace: user error (Can't do Infix Minus)
wspace: user error (Can't do Infix Times)
wspace: user error (Can't do If Zero " ")
wspace: user error (Can't do Infix Divide)
wspace: user error (Can't do Infix Modulo)
wspace: user error (Can't do If Negative " ")
wspace: Input.hs:(108,5)-(109,51): Non-exhaustive patterns in function parseNum'
wspace: Unrecognised input\nCallStack (from HasCallStack):\n  error, called at Input.hs:103:11 in main:Input
wspace: Stack space overflow: current size 33624 bytes.\nwspace: Relink with -rtsopts and use +RTS -Ksize -RTS' to increase it.


NOTE: Whitespace compilers have their own implementations for error messages. All these errors above are on TIO. If I use the online Whitespace compiler vii5ard instead, and use the same program at the top, it will give this error instead:

ERROR: Runtime Error: Stack underflow


So using the vii5ard online Whitespace compiler I could lower my byte-score to:

# Whitespace (on vii5ard), 15 bytes

Unexpected EOF!


Which is the 'program' S (a single space), resulting in the error:

Unexpected EOF


# 05AB1E, 410 411 bytes

One plus one is two, two plus two is four.
And now, some random character spam just because I can.
3...
2...
1...
GO!

ooi1u4o1i2)I#1n[09i43u1@#~!@#{10239]ι@(~!)2ioausioe7u12o3iu71p312371i28127l5ruy;3948'p3298rv9pe8huep'r8i19o8u'3pie8uiouI!^23uT7T17I3YJH~:L'IYU2O123;121@

That should be about it, it errored. Guess that's what happens when you spam. Bye for now!

upvote if you liked my creativity

:)


Try it online!

One plus one i...]ι...  # trimmed program
One plus one            # push empty string ("") twice
i          # if top of stack is truthy...
...       # execute (trimmed) code (this is unreachable)
]      # exit all opened statements
ι     # not exactly sure what this function does, but part of it forcefully converts top of stack to an integer (without error handling), therefore erroring
...  # unreachable code as program has quit from the fatal error


# Error, 410 bytes

** (RuntimeError) Could not convert  to integer.
(osabie) lib/interp/functions.ex:101: Interp.Functions.to_integer!/1
(osabie) lib/interp/commands/special_interp.ex:113: Interp.SpecialInterp.interp_step/3
(osabie) lib/interp/interpreter.ex:127: Interp.Interpretr.interp/3
(osabie) lib/osabie.ex:62: Osabie.CLI.main/1
(elixir) lib/kernel/cli.ex:105: anonymous fn/3 in Kernel.CLI.exec_fun/2



# Aubergine, 53 bytes

0/0 Lots of wasted space. I don't know how Aubergine.


Outputs SyntaxError: Invalid instruction (0) at character 0.

Try it online!