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

1 2 3
4
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\$
    – Adalynn
    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\$ Jul 21, 2017 at 19:49
  • \$\begingroup\$ why am I getting down votes for this? @Zacharý :( \$\endgroup\$ 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\$ 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\$ 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\$
    – Titus
    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\$ Oct 24, 2017 at 16:51
  • \$\begingroup\$ Try akrabat.com/convert-php-warnings-and-notices-into-fatal-errors \$\endgroup\$
    – Titus
    Oct 24, 2017 at 18:34
  • \$\begingroup\$ I´d give +1 for the exact counting, but my vote is locked. \$\endgroup\$
    – Titus
    Oct 24, 2017 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\$
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, 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\$
    – lukass
    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\$ 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\$
    – lukass
    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\$
0
\$\begingroup\$

Python, 35 bytes

Pretty simple.

print(a)###########################

Prints out an undeclared variable then adds a comment to make sure that the error message (NameError: name 'a' is not defined) is shorter than the actual code. I could've probably done better.

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

Whitespace (wspace 0.3), 19 bytes

SSSSL
SLS
TSTS
TLST
LLL

Error: w: divide by zero (18 bytes)

Try it online!

The zero divisor error is the shortest error message produced by the wspace 0.3 reference interpreter (see the yspace project for a survey of other errors). Using mod in place of div would yield an equivalent result. The reference interpreter was written in Haskell, so arithmetic operations are evaluated lazily and it will not panic with divide by zero unless the illegal value is used by an eager instruction—printi in this case. To reach the minimum byte count, push 0 is written as SSSSL and end is appended.

push 0
dup
div
printi
end

Renaming wspace to w gives a shorter error message.

$ ln -s ~/bin/wspace w
$ ./w codegolf/shortest_error.ws
w: divide by zero
$ ./w shortest_error.ws 2>| wc -c
      18
$ wc -c < shortest_error.ws
      19

(This solution is part of the ws-challenges repo)

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