# 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. – Dennis Jul 28 '17 at 16:18
• @Dennis I guess that's one way of solving the "OP doesn't edit clarifications into question" problem. – Ørjan Johansen Jul 29 '17 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. – MD XF Nov 24 '17 at 21:38
• @smartpeople is this: "__main__.CodeException: Raised an &rror." my error or is this:"Raised an &rror." – RaviRavioli Dec 25 '17 at 17:13
• TrumpScript running in China? – Stan Strum Jan 30 '18 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 – totallyhuman Jul 21 '17 at 20:21
• Can ed do addition and primality testing? Or is that not required for this type of challenge? – Stephen Jul 21 '17 at 22:34
• @StepHen Yes, it can do addition and primality testing in unary via the usual regex-with-backreferences trick. – Anders Kaseorg Jul 22 '17 at 0:57
• Very clever, but '?' isn't fatal. – Mark Plotnick Jul 27 '17 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! – Dennis Jul 4 '18 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? – totallyhuman Jul 21 '17 at 20:23
• – Dennis Jul 21 '17 at 21:48
• Are there no other locale with a shorter version (So that you could then use main(){main();})? – 12431234123412341234123 Jul 27 '17 at 13:10
• @12431234123412341234123 Not that I know of. Also, main(){main();} is not guaranteed to seg-fault. – MD XF Jul 30 '17 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. – 12431234123412341234123 Jul 31 '17 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 – hyper-neutrino Jul 21 '17 at 19:44
• This is clever! – Skyler Jul 24 '17 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! – Adalynn Jul 21 '17 at 19:28
• Assuming a 1-char file name, you can golf to this. – Erik the Outgolfer Jul 21 '17 at 19:36
• Heh, nice. - - - – totallyhuman Jul 21 '17 at 19:40
• But the error message has to be smaller than the program itself... – Leaky Nun Jul 21 '17 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.. – boboquack Jul 26 '17 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>>


# 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. – Engineer Toast Jul 21 '17 at 20:00
• @EngineerToast thanks, didn't think of that one. – Stephen Jul 21 '17 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... – ETHproductions Jul 21 '17 at 20:49
• I had the same idea, came up with a=null;a.x01234567890 Same amount of bytes – RuteNL Nov 9 '17 at 13:43

# ><>, 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 :-) – Xan-Kun Clark-Davis Jul 25 '17 at 16:58
• @Xan-KunClark-Davis sigh you had to... :P – hyper-neutrino Jul 25 '17 at 17:26

# 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... – univalence Jul 22 '17 at 17:05
• @MegaMan Updated with explanation. – MD XF Jul 22 '17 at 17:46
• Upvote for actually enlightening explanation. – Xan-Kun Clark-Davis Jul 25 '17 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 – Timtech Jul 26 '17 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! – Stephen Jul 24 '17 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... – Leaky Nun Jul 21 '17 at 20:08 • Byte counts were screwed up, my bad. – totallyhuman Jul 21 '17 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. – Dennis Jul 21 '17 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. – Anders Kaseorg Jul 22 '17 at 18:05
• @Anders Is WIFEXITED(wstatus) equivalent to DIVORCE(alimony) by any chance? – Janus Bahs Jacquet Jul 27 '17 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 – MD XF Jul 23 '17 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

• I was asked three questions in the comments, one of which you asked, but the two you didn't ask both applied to your answer, and not yours. – user72528 Jul 21 '17 at 19:37
• @user72528 Yeah, I found that amusing as well. – AdmBorkBork Jul 21 '17 at 19:38
• You can use a one char file name! – Adalynn Jul 21 '17 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. – AdmBorkBork Jul 21 '17 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). – TessellatingHeckler Jul 21 '17 at 21:34 # 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! – Martin Ender Jul 21 '17 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. – ameketa Jul 23 '17 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. – Eric Duminil Jul 23 '17 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 '17 at 15:16 • @JarkoDubbeldam thank you. – Giuseppe Jul 25 '17 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. – user72528 Jul 21 '17 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 :) – hyper-neutrino Jul 21 '17 at 19:21 • Who beats brainfuck? Nobody? Alright. – Erik the Outgolfer Jul 21 '17 at 19:28 • The unbeatable solution would a two byte solution which causes an error of 1 character. – Adalynn Jul 21 '17 at 19:30 • @Zacharý Certainly lol – hyper-neutrino Jul 21 '17 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. – Adalynn Jul 21 '17 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 – Cheldon Jul 21 '17 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 '17 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)  # 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. 😂 – EasyasPi Jan 5 at 14:20 # Perl 5, 5 bytes die$/


Outputs a newline, for one byte.

Try it online!

• ._. Now ... if only perl errors on the empty file! – Adalynn Jul 22 '17 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. – aschepler Jul 22 '17 at 1:41
• @Zacharý ... giving an error message with total length negative one? – aschepler Jul 22 '17 at 1:54
• This might be invalid ... or not, depends on whether the OP meant the error or the error message – Adalynn Jul 22 '17 at 2:14
• ^ clarification: whether a program errors directly or creates an error message directly – Adalynn Jul 23 '17 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. – sergiol Jul 22 '17 at 17:34
• How is that any different than python raise? – Eric Duminil Jul 23 '17 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. – Adalynn Jul 23 '17 at 14:42

# 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!

# GW-BASIC, 13 bytes

-------------


Error (12 bytes):

Syntax error


As GW-BASIC treats anything it doesn't recognize as a syntax error, there are a near-infinite amount of strings of length 13 that I could've used instead of -------------

# Ruby, 25 bytes

That was a fun exercise, thanks! There's probably a way to get a shorter error message with a SegFault, but I couldn't find any.

/\x
# Invalid hexa regexp


Error message:

a:1: invalid hex escape


24 bytes, including a trailing newline.

Try it online!

# Ruby, 26 bytes

08
# No 8 allowed in octal


Error message:

a:1: Invalid octal digit


25 bytes, including a trailing newline.

• I think you should separate your answers. – Solomon Ucko Jul 24 '17 at 0:51
• @SolomonUcko: Any reason why? There are many answers already. I just wanted to leave a trail of my previous answer. People usually just edit the byte count with <s>26</s> 25, but it's often for minor changes. – Eric Duminil Jul 24 '17 at 7:34
• Actually, I'm not sure why I said that, so nevermind. – Solomon Ucko Jul 30 '17 at 14:00