145
\$\begingroup\$

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 '['
\$\endgroup\$
6
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Dennis
    Jul 28, 2017 at 16:18
  • 1
    \$\begingroup\$ @Dennis I guess that's one way of solving the "OP doesn't edit clarifications into question" problem. \$\endgroup\$ Jul 29, 2017 at 23:52
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – MD XF
    Nov 24, 2017 at 21:38
  • \$\begingroup\$ @smartpeople is this: "__main__.CodeException: Raised an &rror." my error or is this:"Raised an &rror." \$\endgroup\$ Dec 25, 2017 at 17:13
  • 1
    \$\begingroup\$ TrumpScript running in China? \$\endgroup\$
    – Stan Strum
    Jan 30, 2018 at 6:34

116 Answers 116

2
\$\begingroup\$

[/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.

\$\endgroup\$
2
\$\begingroup\$

CPython 3.9, 71 bytes

__peg_parser__
########################################################

Not the shortest, but I found this "feature" worth sharing nonetheless: when Python 3.9 switched to a PEG parser, there was a special easter egg keyword __peg_parser__ added which immediately causes a syntax error. The error outputted is:

  File "a", line 1
    __peg_parser__
    ^
SyntaxError: You found it!

This was removed in Python 3.10.

\$\endgroup\$
1
\$\begingroup\$

Python 3, 71 bytes

a=b=c=d=e=f=g=h=i=j=k=l=m=n=o=p=q=r=s=t=u=v=w=x=y=z=A=B=C=D=E=F=1#
is=0

Try it online!

  File ".code.tio", line 2
    is=0
     ^
SyntaxError: invalid syntax
\$\endgroup\$
2
  • 1
    \$\begingroup\$ You can use a one char file name (TIO ... why) \$\endgroup\$
    – Adalynn
    Jul 21, 2017 at 19:55
  • \$\begingroup\$ @Zacharý /shrug not the shortest anyway, so I might as well make it consistent with TIO to avoid people asking me about the weird difference. I don't really care about bytecount lol \$\endgroup\$
    – hyper-neutrino
    Jul 21, 2017 at 20:06
1
\$\begingroup\$

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!

\$\endgroup\$
1
\$\begingroup\$

Lua, 45 bytes

0/###########################################

Try it online!

Error message, 44 bytes

lua: .code.tio:1: unexpected symbol near '0'
\$\endgroup\$
5
  • \$\begingroup\$ You can use a one char file name! \$\endgroup\$
    – Adalynn
    Jul 21, 2017 at 19:53
  • \$\begingroup\$ I think its better that officialaimm didn't. Beat my example by 1. :P \$\endgroup\$
    – user72528
    Jul 21, 2017 at 19:55
  • \$\begingroup\$ How is it better that he didn't? \$\endgroup\$
    – Adalynn
    Jul 21, 2017 at 19:56
  • 1
    \$\begingroup\$ It's not a better result, I just found it more funny that he beat the example by exactly 1 byte. \$\endgroup\$
    – user72528
    Jul 21, 2017 at 19:59
  • \$\begingroup\$ That would be because I had forgotten the example was in Lua and I don't really know lua... :D \$\endgroup\$ Jul 22, 2017 at 4:05
1
\$\begingroup\$

Haystack, 21 bytes

Wasted space is good!

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

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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.) \$\endgroup\$ Jul 22, 2017 at 16:43
  • \$\begingroup\$ @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. \$\endgroup\$
    – MD XF
    Jul 23, 2017 at 22:11
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
2
  • 3
    \$\begingroup\$ You can use a one char file name \$\endgroup\$
    – Adalynn
    Jul 21, 2017 at 19:55
  • \$\begingroup\$ Yeah, Thanks.... But to make it more TIO-interactive... if you know what I mean.. \$\endgroup\$ Jul 22, 2017 at 4:06
1
\$\begingroup\$

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.

see comments for details...

\$\endgroup\$
9
  • \$\begingroup\$ 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) \$\endgroup\$ Jul 22, 2017 at 3:05
  • \$\begingroup\$ 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. \$\endgroup\$ Jul 22, 2017 at 3:11
  • \$\begingroup\$ I asked the question here: codegolf.stackexchange.com/questions/133840/… \$\endgroup\$ Jul 22, 2017 at 3:18
  • 1
    \$\begingroup\$ @LegionMammal978 Are you going to measure JungHwan's answer, too, (?) or this is just about my answer? \$\endgroup\$
    – ZaMoC
    Jul 22, 2017 at 12:59
  • 2
    \$\begingroup\$ yes, it is quite funny! posting all these things on the main chat and doing exactly the same! \$\endgroup\$
    – ZaMoC
    Jul 22, 2017 at 13:25
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

C++, 26 bytes

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

Result in Windows:

a.exe has stopped working
\$\endgroup\$
1
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

MATLAB, 52 44 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.

\$\endgroup\$
1
  • \$\begingroup\$ I guess this works in MATLAB too? I'm not sure if all work, but I believe some of them should... :) \$\endgroup\$ Nov 9, 2017 at 13:28
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Aceto, 41 bytes

                                        &

Try it online!

Produces __main__.CodeException: Raised an &rror.

The error message is 40 chars, so...

\$\endgroup\$
1
\$\begingroup\$

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.

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

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.

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
0
1
\$\begingroup\$

COBOL(GNU), 47 bytes

PROCEDURE DIVISION. HELLO. HELLO. HELLO. HELLO.

Outputs:

main.cobc: 1: error: PROGRAM-ID header missing

Assuming filename = main.cobc

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
5
  • \$\begingroup\$ I believe the goal is to make the error message shorter than the code. \$\endgroup\$
    – EasyasPi
    Jan 5, 2021 at 14:23
  • \$\begingroup\$ @EasyasPi Fixed \$\endgroup\$
    – Aiden4
    Jan 5, 2021 at 15:20
  • \$\begingroup\$ .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.) \$\endgroup\$ Jun 6, 2021 at 19:10
  • \$\begingroup\$ @AndersKaseorg I think you're right, I found another 61-byte answer. Nice spot, though. \$\endgroup\$
    – Aiden4
    Jun 7, 2021 at 18:45
  • \$\begingroup\$ Your answer works on a slice too: 57 bytes \$\endgroup\$ Jun 7, 2021 at 19:08
0
\$\begingroup\$

Add++, 20 bytes

+?
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.

\$\endgroup\$
0
\$\begingroup\$

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

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

Try it online!

Produces the error

BrainHack: Prelude.chr: bad argument: (-1)
\$\endgroup\$
0
\$\begingroup\$

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

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

Zsh, 24 bytes

"" #lots of wasted space

Outputs zsh: permission denied:.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Tcl/Tk, 19

pack [text .text 1]

outputs

18

unknown option "1"
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.