141
\$\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 '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\$ – RaviRavioli Dec 25 '17 at 17:13
  • 1
    \$\begingroup\$ TrumpScript running in China? \$\endgroup\$ – Stan Strum Jan 30 '18 at 6:34

112 Answers 112

1 2 3
4
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
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\$
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\$ – RuteNL Nov 9 '17 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\$ – lukass Jun 27 '18 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\$ – Ciaran_McCarthy Jun 27 '18 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\$ – lukass Jun 27 '18 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\$
0
\$\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 2 3
4

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.