151
\$\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\$ Commented 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\$ Commented 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\$ Commented Nov 24, 2017 at 21:38
  • \$\begingroup\$ @smartpeople is this: "__main__.CodeException: Raised an &rror." my error or is this:"Raised an &rror." \$\endgroup\$ Commented Dec 25, 2017 at 17:13
  • 1
    \$\begingroup\$ TrumpScript running in China? \$\endgroup\$ Commented Jan 30, 2018 at 6:34

129 Answers 129

1
\$\begingroup\$

Pip, 65 bytes

Fatal error while parsing: Unterminated list Execution aborted. [ 

Outputs the following 64-byte error message:

Fatal error while parsing: Unterminated list Execution aborted. 

Attempt This Online!

The problem is the [ without a matching ], which causes a syntax error. Everything else is valid Pip code; if the missing ] were added, the program would run successfully and output nothing (empty list joined into a string) followed by a newline.

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

Bespoke, 17 bytes

go out with error 

This program is equivalent to the "mnemonic" code DO ROT; PUSH FIFTH. When DO ROT is run on the empty stack, it errors out with the 16-byte error message Stack underflow..

\$\endgroup\$
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\$ Commented Jul 21, 2017 at 19:31
  • \$\begingroup\$ This is C++ code! \$\endgroup\$ Commented Jul 21, 2017 at 19:53
  • \$\begingroup\$ @Zacharý Oups! Thanks for the correction! \$\endgroup\$ Commented Jul 21, 2017 at 19:57
  • \$\begingroup\$ And ... you can use a one char file name. \$\endgroup\$ Commented Jul 21, 2017 at 19:58
  • \$\begingroup\$ Would this work? printf("%s", variable)=>printf("%s",variable)? \$\endgroup\$ Commented 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\$
0
\$\begingroup\$

Tcl, 15

if 1234567890/0 

outputs

divide by zero 
\$\endgroup\$
0
\$\begingroup\$

Ly, 77 bytes

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

Outputs:

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

(note the trailing newline)

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

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\$
0
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\$
1
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\$
4
  • \$\begingroup\$ -1: That´s not a fatal error. \$\endgroup\$ Commented Oct 24, 2017 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\$ Commented Oct 24, 2017 at 16:51
  • \$\begingroup\$ Try akrabat.com/convert-php-warnings-and-notices-into-fatal-errors \$\endgroup\$ Commented Oct 24, 2017 at 18:34
  • \$\begingroup\$ I´d give +1 for the exact counting, but my vote is locked. \$\endgroup\$ Commented Oct 24, 2017 at 20:40
0
\$\begingroup\$

><>, 26 Bytes

Code: "we'refinehereuntilthis!"z

Error: Something smells fishy...

All ><> errors are Something smells fishy...

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

JavaScript, 13 bytes

prompt(alert( 

Error produced (12 bytes):

Expected ')' 
\$\endgroup\$
1
  • \$\begingroup\$ Which browser? Firefox gives: SyntaxError: expected expression, got end of script \$\endgroup\$ Commented Nov 9, 2017 at 13:51
0
\$\begingroup\$

Julia 0.6 (REPL/-e), 20 bytes

print(factorial(-9)) 

produces:

ERROR: DomainError: 

(assuming stacktraces don't count) which is 19 bytes.


Older answer, 22 bytes:

println(Int(Inf)+0123) 

Produces

ERROR: InexactError() 

which is 21 bytes.


Trivial answer, 7 bytes (probably falls short of "The error message may not be generated by the program itself, such as Python's raise" requirement):

error() 

produces

ERROR: 
\$\endgroup\$
0
\$\begingroup\$

Attache, 40 bytes

A Reference Error: Undefined variable!!! 

Try it online!

Message (39 bytes): Reference Error: Undefined variable "A"

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

Go, 36 bytes

package verylongnamednonmainpackage; 

Produces:

go run: cannot run non-main package 
\$\endgroup\$
0
\$\begingroup\$

F#, 29 bytes code, 28 bytes error message

let [<EntryPoint>] main a=1/0 

Generates the runtime Exception message:

Attempted to divide by zero. 

+5 bytes thanks to lukass.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ The question requires an error message shorter than the program: > Write the shortest program that, when compiled or executed, produces a fatal error message smaller than the program itself. \$\endgroup\$ Commented Jun 27, 2018 at 13:14
  • 1
    \$\begingroup\$ I've no idea why, but I read the question as "longer". Damn. Now that I think about it, that makes more sense as a challenge too... \$\endgroup\$ Commented Jun 27, 2018 at 13:17
  • \$\begingroup\$ Golfing the combined length of a program and its longer error message would actually be interesting. Write a longer program to generate a shorter message is a cool tradeoff :) \$\endgroup\$ Commented Jun 27, 2018 at 15:37
0
\$\begingroup\$

Coconut, 48 bytes

Code:

+ CoconutParsererErrorr: parsing failed (line 1) 

Prints error (47 bytes):

CoconutParseError: parsing failed (line 1) + 

with a trailing newline

Try it online!

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

Loader, 50 bytes

load t This is line not executed because of error. 

Assumptions:

  • The program is run from a file with a one-byte name
  • The module named t does not exist.

The error message (assuming you run from a module named m) is:

Error: module t does not exist (module m, line 1) 
\$\endgroup\$
0
\$\begingroup\$

C# .NET, 59 bytes

public class P{static void Main(){int je=0;int iee=je/je;}} 

Try Online
Produces the following error (58 bytes):

System.DivideByZeroException: Attempted to divide by zero. 

(NOTE: I am not counting in the stacktrace that the .NET Compiler generates)

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

Python, 30 bytes

import math as ma; ma.sqrt(-1) 

Error: ValueError: math domain error (29 bytes)

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

GNU Smalltalk, 26 bytes

Create a source file _ with underscores:

__________________________ 

Running gst _, the error is 25 bytes including ␤:

_:1: expected expression 

Underscore was originally mapped to , the assignment operator prior to :=.

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

C, Bionic libc (Android, Termux), 16 characters

main(){free(1);} 

Output, 8 characters (including newline)

Aborted 
\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.