# 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." – FantaC Dec 25 '17 at 17:13
• TrumpScript running in China? – Stan Strum Jan 30 '18 at 6:34

# Tcl, 15

if 1234567890/0


outputs

divide by zero


# Ly, 77 bytes

[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[


Outputs:

Error occurred during parsing
SyntaxError: unmatched [] brackets in program



(note the trailing newline)

# C/*nix, 13 bytes

f(){free(f);}


On minimalist/old systems and shells that don't do fancy things, this prints:

Aborted


Of course, most modern shells print things like:

*** Error in /tmp/file': munmap_chunk(): invalid pointer: 0x0000000000400536 ***
Aborted


TryItOnline prints a whole host of information.

• Can you give an example of a system that only prints Aborted? (Without the specific checks that glibc uses to detect invalid the free and cleanly call abort(), the program would almost certainly just segfault.) – Anders Kaseorg Jul 22 '17 at 16:43
• @AndersKaseorg I'm trying to remember on which system this didn't print extra information. I'm not at home so I don't have my ... extensive computer collection, when I get home I'll test it all around. – MD XF Jul 23 '17 at 22:11

# Python 3, 67 bytes


File ".code.tio", line 1
^
SyntaxError: invalid syntax


Try it online!

### Error Message, 66 bytes

  File ".code.tio", line 1

^
SyntaxError: invalid syntax

• You can use a one char file name – Zacharý Jul 21 '17 at 19:55
• Yeah, Thanks.... But to make it more TIO-interactive... if you know what I mean.. – officialaimm Jul 22 '17 at 4:06

## Batch, 24 23 bytes

@dir                  /


Outputs the following 23 22-byte error (as calculated by redirecting the output to a file):

Invalid switch - "".


Edit: Saved 1 byte by not having a switch character at all.

# Casio Basic, 10 bytes

{}=>a:a[1]


or, for 12 bytes:

seq(x,x,1,0)


Error for both (6 bytes):

Domain


For the first one, accessing a list element outside the length of the list throws a Domain error. But for some weird reason, you can't access a list index in one go; that is, {}[1] is invalid syntax.

seq generates a list of values for a function with values in a given range; but in this case, specifying a range of 1 to 0 causes a Domain error, since the end is smaller than the start.

# Mathematica kernel, 36 bytes

ClearAll[f];(*Space Filler*)On[f::f]


and the error is 35 bytes:

(linebreak)On::none: Message f::f not found.(linebreak)


# Braingolf, 54 bytes

"ZeroDivisionError: integer division or modulo by z"0/


Try it online!

Throws the 53 byte error ZeroDivisionError: integer division or modulo by zero

## Explanation

"ZeroDivisionError: integer division or modulo by z" is a string literal, pushes the error minus 3 bytes.

0 pushes 0, and / attempts to divide the 2nd to last item by the last item, in this case dividing z (122) by 0, which results in a divide by zero error.

# Braingolf, 84 bytes

"ValueError: Indices for islice() must be None or an integer: 0 <= x <= sys.maxs"&@@


Try it online!

I personally get this error quite often when screwing around with ASCII art challenges in Braingolf.

Throws a ValueError: Indices for islice() must be None or an integer: 0 <= x <= sys.maxsize. error.

## Explanation

"ValueError: Indices for islice() must be None or an integer: 0 <= x <= sys.max" is a string literal. It's just the error minus 4 bytes, because the code must be longer than the error.

&@ then pops and prints the entire stack.

Finally @ attempts to pop and print an item from the now empty stack. Popping from an empty stack produces the above 83 byte error.

# C++, 26 bytes

int main(){div(1,0);} //??


Result in Windows:

a.exe has stopped working


# VBA, 29 Bytes

Anonymous VBE immediate window function of length 29 which throws Runtime error 6, (len 28) to STDERR

### Code

?CByte(Len(Space(127+128+1)))


### Error

Run-time error '6':

Overflow

# Prolog (SWI), 26 bytes (error: 25 bytes)

a :- a ; a ; a ; a ; a ;a.


Try it online!

This will generate the error: ERROR: Out of local stack (which is, as far as I know, the shortest error message that can be generated by SWI-Prolog).

### Explanation

The above program can be simplified to a :- a ; a. (the other ; as are here so that the program is longer than the error message).

The above program says:

a :-      .        % For a to be true…
a             % Either a…
;           % …or…
a         % …a must be true


This is obviously infinitely recursive, hence why we get an Out of local stack error.

However, the following program:

a :- a.


is also infinitely recursive but will never crash. This is because in that case, tail recursion optimization occurs so that the recursive call does not consume memory.

a :- a ; a. is also tail recursive; however we have introduced a disjunction with ; which prevents the recursive call from not consuming memory, because Prolog has to remember that there was another choice possible to explore instead of each recursive call.

It is possible to generate this same error with other approaches (e.g. using length(_,1000000000) to generate a list too big to fit in memory), but this one is probably the coolest looking one.

# Groovy, 69 bytes

java.lang.Class.metaClass=Integer.metaClass
Integer.metaClass.plus={1}


Error message is:

java.lang.StackOverflowError


I don't know if this will count at 31 bytes, because it will output a lot of line numbers:

a​aaaaaa={aaaaaaa()}​;aaaaaaa()


Output:

java.lang.StackOverflowError
at Script1$_run_closure1.doCall(Script1.groovy:1) at Script1$_run_closure1.doCall(Script1.groovy)
at Script1$_run_closure1.doCall(Script1.groovy:1) at Script1$_run_closure1.doCall(Script1.groovy)
...


## JAVA 8, 137 bytes error and 138 bytes code

package a;

public class a{
public static void main(String[] args){
String f = "sdfgsfdgdffffffffffffffffffffffffsfdgfd";
a = 5;
}
}


produces the error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
a cannot be resolved to a variable

at a.a.main(a.java:6)


as this is my first time please tell me if i did something wrong

# MATLAB, 5244 43 bytes

Another shorter option is to use a function and not provide enough inputs. For example:

qr()%I'm a nice comment to make code longer


Gives this 42 byte error:

Error using qr
Not enough input arguments.


This code (or to be fair any similar code:

[1 1]*[2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ]


Produces the following 51 byte error:

Error using  *
Inner matrix dimensions must agree.


It's actually surprisingly tricky in MATLAB because when you run any code with syntax errors the error output includes the line of code you ran - which would put a theoretical lower limit on code size of infinity. Fortunately matrix multiplication errors don't do that.

• I guess this works in MATLAB too? I'm not sure if all work, but I believe some of them should... :) – Stewie Griffin Nov 9 '17 at 13:28

# C# (.Net, Mono) 25 bytes

class Hi{void There(){_}}


Error:

error CS1002: ; expected


Note: Mono error messages include filename and location before them, so if you named the file P.cs, you'd get this error:

P.cs(1,24): error CS1002: ; expected


Since that part depends on the filename and location of text, I didn't include it. However, if you include it (and make the class name longer or something), you end up with a 36 byte error message and 37 byte program. Let me know if I should change it to that.

# 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


# ed, 3 bytes

?



Returns the following error message (2 bytes).

?



ed is Turing complete, so there shouldn't be issues about whether using it is valid or not. There was a solution in ed before, but it was removed, as there was a concern whether this is a fatal error. I would say, yes, it is, no matter what I did on TIO.run, the execution did not continue after getting an error message. From checking why this happens, it appears that the execution continues only when the code is read from STDIN (REPL mode).

Inspired by https://www.gnu.org/fun/jokes/ed-msg.html

Try it online!

Note that the output contains 0, but it's not a part of an error message, rather it's ed displaying file size by default. It can be removed by using -s flag. If you try changing the input provided to the program, it will change.

### Sinclair ZX81 - 8 bytes4 bytes 2 bytes (2 BASIC tokens) using direct mode:

 PRINT A


Less old solution

 PRINT A+A


Old solution (8 bytes of memory):

 1 PRINT A


When you enter the command RUN, the following error is reported:

2/1


as in the screen shot below - Error code 2 means "Undefined variable" or something similar.

# IE9 Chinese version, 9 bytes

'12345'()


Outputs (assuming GBK encoding)

缺少函数


# Bash, 20 bytes

"" # waste of space!


Outputs : command not found.

Try it online!

# Bash, 21 bytes

b # let's waste space


Outputs: b: command not found.

Try it online!

# Zsh, 24 bytes

"" #lots of wasted space


Outputs zsh: permission denied:.

Try it online!

# Haystack, 21 bytes

Wasted space is good!


Errors with Where's the needle?. Dosen't work on TIO.

# Python 2, 67 bytes

b(h)#This has to be 67 characters. Thus, I'm writing this bullshit.


# Error message, 66 bytes

  File ".", line 1, in <module>
NameError: name 'b' is not defined


Note: doesn't work on TIO. Gives a longer error message. Try Python 2.7.13 on a local machine from stdin.

• You can assume a one-char file name. – Zacharý Jul 21 '17 at 19:48
• Then it gets reduced by 8 bytes. I think I can get rid of the last '. HAHAHA' then – Koishore Roy Jul 21 '17 at 19:49
• why am I getting down votes for this? @Zacharý :( – Koishore Roy Jul 22 '17 at 16:19
• I wasn’t the downvoter, but with a local Python 2.7.13 and stdin, I get a 108-byte error: Traceback (most recent call last):⏎␣␣File "<stdin>", line 1, in <module>⏎NameError: name 'b' is not defined⏎. – Anders Kaseorg Jul 22 '17 at 18:10
• Which other answer in Python? The tracebacklimit answer is clever precisely because it suppresses that portion, and the answers based on SyntaxErrors don’t have a traceback to begin with because the error is from the parser. – Anders Kaseorg Jul 24 '17 at 1:06

# 4, 14 bytes

3.141592653589


All 4 programs must start with 3. and end with 4.

Provides as error (when run with the provided python interpreter)

Code invalid.


# Applesoft BASIC, 14 bytes

SYNTAX ERROR??


Output:

?SYNTAX ERROR


# ExtraC, 21 bytes

Invalid character: :


Try it online!

If you remove the space after the second :it is a error quine

# Javascript 79 bytes

clear(this);
a=0;
typein:2: TyperError: attempt to run compile-and-go script on a


# C++ (MinGW + GCC + Windows), compile time, 38 3946 bytes

According to OP's comment, it seems OK to assume the file is stored in a designated path. The code needs to be saved in a 8-byte location such as D:\a.cpp.

#if 1/*aaaaaaaaaaaaaaaaaaaaaaaaaaaaa*/


Error message:

D:\a.cpp:1:0: error: unterminated #if


The principle should work on other platforms.

# PHP, 47 Bytes

<?php echo 'program including divide by 0',1/0;

produces:

PHP Warning: Division by zero in - on line 1 plus a newline.

• -1: That´s not a fatal error. – Titus Oct 24 '17 at 16:41
• Actually, you're right. Warnings aren't fatal. In a quick search I haven't found the right setting yet... – manassehkatz-Reinstate Monica Oct 24 '17 at 16:51
• – Titus Oct 24 '17 at 18:34
• I´d give +1 for the exact counting, but my vote is locked. – Titus Oct 24 '17 at 20:40

# Vim, 19 bytes?

:print "ex command


With a trailing newline, this prints the current line to the messages window. If the buffer is empty, it shows E749: empty buffer instead. The " starts a comment.

I'm an very unsure how to count the number of bytes both in the input and error message. The command can be run as vim +"print \"ex command" (17 bytes?), but this adds an additional line to the error message: Error detected while processing command line: (total 62 bytes?).

Alternatively, the command can be put in a file and run the the following hack to trick Vim it is user input: cat cmd.vim - | vim --not-a-term. Without --not-a-term Vim writes Vim: Warning: Input is not from a terminal.

I didn't count the error message length including a newline since Vim won't write a newline to the screen; it uses ncurses or similar to directly draw at specific coordinates.

There is one potentially shorter error message: E572: Exit code %d. It can be triggered by :tcl, but I'll leave it to someone who has +tcl` enabled.