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

103 Answers 103

1
\$\begingroup\$

Tcl, 15

if 1234567890/0

outputs

divide by zero
\$\endgroup\$
1
\$\begingroup\$

Ly, 77 bytes

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

Outputs:

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

(note the trailing newline)

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

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.

\$\endgroup\$
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\$

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)
\$\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
\$\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\$
  • \$\begingroup\$ I guess this works in MATLAB too? I'm not sure if all work, but I believe some of them should... :) \$\endgroup\$ – Stewie Griffin Nov 9 '17 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\$

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: Prelude.chr: bad argument: (-1)
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

(Which would result in wspace: Unrecognised input\nCallStack (from HasCallStack):\n error, called at Input.hs:103:11 in main:Input on TIO).

\$\endgroup\$
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\$

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

Newest solution

 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.

ZX81 Undefined Variable error

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

IE9 Chinese version, 9 bytes

'12345'() 

Outputs (assuming GBK encoding)

缺少函数
\$\endgroup\$
0
\$\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\$
0
\$\begingroup\$

Zsh, 24 bytes

"" #lots of wasted space

Outputs zsh: permission denied:.

Try it online!

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

Haystack, 21 bytes

Wasted space is good!

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

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

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.

\$\endgroup\$
  • \$\begingroup\$ You can assume a one-char file name. \$\endgroup\$ – Zacharý Jul 21 '17 at 19:48
  • 3
    \$\begingroup\$ Then it gets reduced by 8 bytes. I think I can get rid of the last '. HAHAHA' then \$\endgroup\$ – Koishore Roy Jul 21 '17 at 19:49
  • \$\begingroup\$ why am I getting down votes for this? @Zacharý :( \$\endgroup\$ – Koishore Roy Jul 22 '17 at 16:19
  • \$\begingroup\$ 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⏎. \$\endgroup\$ – Anders Kaseorg Jul 22 '17 at 18:10
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Anders Kaseorg Jul 24 '17 at 1:06
0
\$\begingroup\$

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

Applesoft BASIC, 14 bytes

SYNTAX ERROR??

Output:

?SYNTAX ERROR
\$\endgroup\$
0
\$\begingroup\$

ExtraC, 21 bytes

Invalid character: : 

Try it online!

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

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

Javascript 79 bytes

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

C++ (MinGW + GCC + Windows), compile time, 38 39 46 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.

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

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.

\$\endgroup\$
  • \$\begingroup\$ -1: That´s not a fatal error. \$\endgroup\$ – Titus Oct 24 '17 at 16:41
  • \$\begingroup\$ Actually, you're right. Warnings aren't fatal. In a quick search I haven't found the right setting yet... \$\endgroup\$ – manassehkatz-Reinstate Monica Oct 24 '17 at 16:51
  • \$\begingroup\$ Try akrabat.com/convert-php-warnings-and-notices-into-fatal-errors \$\endgroup\$ – Titus Oct 24 '17 at 18:34
  • \$\begingroup\$ I´d give +1 for the exact counting, but my vote is locked. \$\endgroup\$ – Titus Oct 24 '17 at 20:40
0
\$\begingroup\$

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.

\$\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.