# 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

# Haystack, 21 bytes

Wasted space is good!


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

# 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

# 2Col, 50 bytes

Invalid code!
Line 0 contains invalid 2Col code!
1


Try it on 2ColIDE

Outputs:

Invalid code!
Line 0 contains invalid 2Col code!


With a trailing newline.

## Explanation

2Col only really has 1 error, and it's caused by the structure of the code being wrong. 2Col expects every line to be exactly 2 characters long, so if a line is longer or shorter than that, you get the above error.

Given that for this challenge the code must be longer than the error, the easiest way to achieve that is to use the error itself and add a byte.

# 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 – Adalynn 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

# Mathematica, 120 bytes

"Take it easy my brother JungHwan Min,Take it easy my brother LegionMammal978,Take it easy my brother Charlie"*666*666/0


error-> Power::infy: Infinite expression 1/0 encountered.

• Your program has to be longer; the exact error message is Power::infy: Infinite expression 1/0 encountered. (on Mathematica Kernel or Mathematica REPL 10.3 and before. The error is Power: Infinite expression 1/0 encountered. on Mathematica REPL 11 and onwards) – JungHwan Min Jul 22 '17 at 3:05
• And the above two error messages ignore the FractionBox; it's up to the OP to decide whether the FractionBox component has to be implemented. – JungHwan Min Jul 22 '17 at 3:11
• I asked the question here: codegolf.stackexchange.com/questions/133840/… – JungHwan Min Jul 22 '17 at 3:18
• @LegionMammal978 Are you going to measure JungHwan's answer, too, (?) or this is just about my answer? – ZaMoC Jul 22 '17 at 12:59
• yes, it is quite funny! posting all these things on the main chat and doing exactly the same! – ZaMoC Jul 22 '17 at 13:25

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

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

# Aceto, 41 bytes

                                        &


Try it online!

Produces __main__.CodeException: Raised an &rror.

The error message is 40 chars, so...

# SmileBASIC console, 12 11 bytes

?@L*EXP(22)


Error message (8 or 9 bytes):

Overflow


Must be run from the console, otherwise it outputs a line number. Normally errors are formatted like {error} in {slot}:{line}({func}:{arg}), but this error isn't caused by a function and doesn't have a line number so only the error name is shown.

EXP(x) returns e^x, and e^22 is 3584912846.131588. This is outside the 32 bit signed integer range of -2147483648 to 2147483647. Multiplying a string (@L) by this value converts it to an integer, causing an overflow error.

• I'd consider calling the language SmileBASIC (DIRECT), since REPLs and similar environments are considered separate languages. – snail_ Jun 26 '18 at 20:51
• Also, you can get the same error with I%=999E99 for 9 bytes. – snail_ Jun 26 '18 at 20:52
• The console isn't a REPL though. – 12Me21 Jun 26 '18 at 21:29
• "REPLs and similar environments" it's close enough that I'd count it, since it is "type in a statement and it runs" – snail_ Jun 27 '18 at 4:06

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

# Shakespeare Programming Language, 100 bytes

,.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck]Ajax:You cat!You is the quotient betweenyou zero.


Try it online!

which produces

Runtime error at line 1: Unable to divide 1 by zero!


The error is 53 bytes including the trailing newline.

I really don't see how this can be improved (unless I missed something obvious). It loads 1 into Puck and attempts to divide him by 0.

# [/bin/sh ("dash" on Ubuntu Bionic)], 20 bytes

cd /;ok="okokokok";@


Output is:

sh: 1: @: not found


The cd / command it just to make sure to switch to a location where there isn't a file named @ since that's effectively what causes the error.

# naz, 38 bytes

1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a4x


Explanation

1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a   # Add 1 to the register 18 times
4x # Set the current opcode to 4


The only opcodes accepted by the naz interpreter under any circumstances are 0 (normal operation), 1 (function write), 2 (variable write), and 3 (conditional). Thus, if run from a file with a one-letter filename (e.g. f.naz), this program will produce the following 37-byte error:

error: invalid opcode
at f.naz:1:38


# Rust, 61 57 bytes

fn main()->Result<(),usize>{[].binary_search(&0)?;Ok(())}


Try it online!

Returns from the main function with Error: 0.

-3 bytes thanks to Anders Kaesorg

• I believe the goal is to make the error message shorter than the code. – EasyasPi Jan 5 at 14:23
• @EasyasPi Fixed – Aiden4 Jan 5 at 15:20
• .ok_or(0) seems like it breaks the rule that “the error message may not be generated by the program itself”. (But if not, 47 bytes.) – Anders Kaseorg Jun 6 at 19:10
• @AndersKaseorg I think you're right, I found another 61-byte answer. Nice spot, though. – Aiden4 Jun 7 at 18:45
• Your answer works on a slice too: 57 bytes – Anders Kaseorg Jun 7 at 19:08

+?
Needed to be long


Try it online!

Error is Error encountered! followed by a newline, which is 19 bytes long. This happens because it tries to take input, but fails as there is no input.

# Brain-Flak (BrainHack), 43 + 3 = 46 bytes

([()])()()()()()()()()()()()()()()()()()()-


Try it online!

Produces the error

BrainHack: Prelude.chr: bad argument: (-1)


# C++ 133 bytes

#include <iostream>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[]){
printf("%s", variable);
return 0;
}


Displays the error (132 bytes):

.code.tio.c: In function ‘main’: .code.tio.c:5:14: error: ‘variable’ undeclared (first use in this function) printf("%s", variable);

• The code must be at least one byte longer than the error message. – Adalynn Jul 21 '17 at 19:31
• This is C++ code! – Adalynn Jul 21 '17 at 19:53
• @Zacharý Oups! Thanks for the correction! – Ivan Botero Jul 21 '17 at 19:57
• And ... you can use a one char file name. – Adalynn Jul 21 '17 at 19:58
• Would this work? printf("%s", variable)=>printf("%s",variable)? – Adalynn Jul 21 '17 at 20:27

# Zsh, 24 bytes

"" #lots of wasted space


Outputs zsh: permission denied:.

Try it online!

# Tcl/Tk, 19

pack [text .text 1]


outputs

# 18

unknown option "1"


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

# 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. – Adalynn 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