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

119 Answers 119

3
\$\begingroup\$

Aubergine, 53 bytes

0/0 Lots of wasted space. I don't know how Aubergine.

Outputs SyntaxError: Invalid instruction (0) at character 0.

Try it online!

\$\endgroup\$
3
\$\begingroup\$

GW-BASIC, 13 bytes

-------------

Error (12 bytes):

Syntax error

As GW-BASIC treats anything it doesn't recognize as a syntax error, there are a near-infinite amount of strings of length 13 that I could've used instead of -------------

\$\endgroup\$
3
\$\begingroup\$

Ruby, 25 bytes

That was a fun exercise, thanks! There's probably a way to get a shorter error message with a SegFault, but I couldn't find any.

/\x
# Invalid hexa regexp

Error message:

a:1: invalid hex escape

24 bytes, including a trailing newline.

Try it online!

Ruby, 26 bytes

Here's my previous answer:

08
# No 8 allowed in octal

Error message:

a:1: Invalid octal digit

25 bytes, including a trailing newline.

\$\endgroup\$
3
  • \$\begingroup\$ I think you should separate your answers. \$\endgroup\$ Jul 24, 2017 at 0:51
  • \$\begingroup\$ @SolomonUcko: Any reason why? There are many answers already. I just wanted to leave a trail of my previous answer. People usually just edit the byte count with <s>26</s> 25, but it's often for minor changes. \$\endgroup\$ Jul 24, 2017 at 7:34
  • \$\begingroup\$ Actually, I'm not sure why I said that, so nevermind. \$\endgroup\$ Jul 30, 2017 at 14:00
3
\$\begingroup\$

Bash, 29 bytes

true&&false||false||a

error message:

a: command not found

it's really just filler of bash builtins before using an undefined command. This was the shortest bash error message I could think of.

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

TRS-80 Model 100 Basic, 10 bytes

Enter this:

??????????

Resulting error message:

?SN Error

All Basic error codes on this charming little machine are retrieved by using the error code to index into an array in ROM that looks like NFSNRG... and so on, so all error codes must be exactly 2 characters. With the 7 extra characters taken into account, all error messages will always be 9 bytes and hence 10 bytes is the shortest possible on this machine.

This is just one way to do it; there are countless more. It generates error 2, code SN, which means syntax error.

\$\endgroup\$
3
\$\begingroup\$

C++ (on macOS High Sierra beta), 23 characters

int main(){*(int*)0=0;}

Output: (22 characters)

Segmentation fault: 11

I do not recall whether previous versions of macOS provide the more traditional Segmentation fault (core dumped) response but adding spaces to the code to pad that out is pretty trivial.

\$\endgroup\$
3
\$\begingroup\$

LibreOffice Calc, 7 bytes

=aaaaaa

Result:

#NAME?
\$\endgroup\$
3
\$\begingroup\$

R, 9 bytes

[edited, because I can't count to 8]

code (9 bytes):

stop();;;

output (8 bytes, including trailing space and newline):

Error: 

According to the manual, "stop stops execution of the current expression and executes an error action." The first argument is meant to be an error message, but can be omitted.

\$\endgroup\$
3
\$\begingroup\$

BASIC (BBC micro) 9 bytes

>REN 9,-5
Silly.
\$\endgroup\$
3
\$\begingroup\$

dc (GNU 1.2) on Windows 10 x64, 185 bytes

dc doesn't crash fatally very often, and I couldn't be bothered to remember code that causes a segfault. I did recall some weird behavior involving arrays that causes a sad and total loss of the current session.

zzz zzzzzzz zz zzzzz zzzzz zzzzzzzzzz

zzzz zzzzzzzzzzz zzz zzzzzzzzz zzz zzzzzzz zz zzzzzzzzz zz zz zz zzzzzzz zzzz
zzzzzz zzzzzzz zzz zzzzzzzzzzzzz zzzzzzz zzzz zzz zzzz zzzzzzzz:zlz

Pushes numbers on the stack until the last five characters. :z stores the second-to-topmost number in the topmost-indexed slot in the array named z. Typically, this array would be linked through time and space to the current instance in the register named z. However, we haven't actually put anything there. Next, we try to lz, or copy the value on top of z to the top of the main stack. We can't: there's nothing there. I'm not sure why this mechanism triggers the failure that it does, but it works. (Or...doesn't.) The trailing newline is significant for two reasons: it puts the code in the black at 185, and pasting it into dc causes it to crash immediately.

Basically, we're running across a canyon, and as long as we don't look down, we're good. But once we look and realize we're floating in mid-air, we fall and crash hard, and little stars zoom around our poor befuddled heads.

Error, 184 bytes

dc: garbage in value being duplicated

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

I'm not sure if only part of that is the actual error or what, so feel free to correct me. The code is obviously very flexible when it comes to length.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ I was messing with this yesterday, and looking through the source for the shortest errors. I guess it's possible that Win10 GNU dc actually has that massive error, but if it's anything like the dcs I've crashed in the same way the past couple of days and like the source I was cruising, that last bit is in fact your shell. zsh on Darwin just gives me a 'zsh: abort dc'; zsh on cygwin gave me some core dump error there. So yeah, I think you can golf it down a bit (but I do believe that error is the shortest/only(?) fatal error). \$\endgroup\$
    – brhfl
    Jul 27, 2017 at 2:19
3
\$\begingroup\$

TI-Basic, 9 bytes

Shortest error messages are 8 bytes each: ERR:DATE, ERR:MODE, ERR:STAT, and ERR:ZOOM. I didn't consider ERR:DATE because that doesn't work on models without an internal clock. Also, I didn't go for ERR:ZOOM because it seemed too hard to trigger.

Program (9 bytes):

Seq:DrawInv X:::::

Error message: ERR:MODE (8 bytes)

Program (9 bytes):

median({1},{0::

Error message: ERR:STAT (8 bytes)

\$\endgroup\$
3
\$\begingroup\$

Shakespeare Programming Language, 48 bytes

,a.Ajax,a.Act I:a.Scene I:a.[Enter Ajax]I error!

Try it online!

Produces:

Unrecognized error encountered. No code output.

There's not much we can do about creating runtime errors, because the minimum overhead to create a program with two characters is 56 bytes, and you can't do much with one character. Instead, we settle for confusing the compiler, which means finding a sentence structure which doesn't fit the grammar rules. In this case, anything that isn't a character name after a character enters the stage.

Shorter error messages exist, for example Error at line 1: act expected, but the code compiled isn't valid, so you get an extra few lines of gibberish after the first error message.

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

IE9 Chinese version, 9 bytes

'12345'() 

Outputs (assuming GBK encoding)

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

Vim, 17 bytes

            :w {

Try it online!

When you write to a file and you have an unmatched starting curly brace in the filename, it will give the error E220: Missing }. The code to get this error is very short, so we just pad it out with spaces to get to the length we want. You can't see this error on TIO, but it works in the terminal.

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

Brain-Flak, 46 bytes

))))))))))))))))))))))))))))))))))))))))))))))

Try it online!

This prints

Error at character 0: Unopened ')' character.

because in Brain-flak, all brackets must be balanced for the program to be valid.

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

J, 10 bytes

0000000^.0

NaN error <-------- length 9

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

Japt, 32 bytes

????????????????????????????????

Error message (31 bytes):

SyntaxError: Unexpected token ?

Try it online!

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

Rexx (Regina), 25 bytes

interpret interpret 2+3+1

Try it online!

"interpret" treats the text following it as source and tries to execute it. Since 2+3+1 is not included in quotes it treats it as a calculation and does that first. Resulting in "interpret interpret 6" The first "interpret" tells REXX to treat "interpret 6" as source. So it executes it. This results in the attempt to execute 6 as source.

sh: 6: command not found
\$\endgroup\$
2
\$\begingroup\$

C#, 46 bytes

class P{public static int Main(string[]arg){}}

And produces the error at 45 bytes:

'P.Main()': not all code paths return a value

Probably a shorter way to do this in C# but I can't think of it.

\$\endgroup\$
2
  • \$\begingroup\$ You can remove the public and string[]arg. Also, leaving off a semicolon gives you this error instead: error CS1002: ; expected. In fact, you can remove the static, give it any type, and rename the function to anything you want to put your byte count above the error message length. \$\endgroup\$
    – TehPers
    Jul 26, 2017 at 16:46
  • 1
    \$\begingroup\$ @TehPers that sounds like a sufficiently different approach that you could make it an answer. \$\endgroup\$
    – CompuChip
    Jul 27, 2017 at 7:04
2
\$\begingroup\$

Java 7, 43 bytes

Based on a comment from the OP, we are allowed to assume the filename is 1 character long. This program has that assumption and my example uses the source code's filename z.java

// public static void main(String[] args){}

Error message:

Error: Could not find or load main class z
\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

Batch 90 18 bytes

@set/ab=1+*2*3*4*5

Missing Operand\ Golfed by SteveFest

\$\endgroup\$
3
  • \$\begingroup\$ This shold work: @set/ab=1+2+345) - Missing Operand \$\endgroup\$
    – stevefestl
    Jul 27, 2017 at 0:39
  • \$\begingroup\$ I was wrong: @set/ab=1+*2*3*4*5 - Missing Operator It's just as few bytes. I'm sorry :( \$\endgroup\$
    – stevefestl
    Jul 29, 2017 at 5:06
  • 1
    \$\begingroup\$ @SteveFest that is fine XD \$\endgroup\$
    – user63187
    Jul 29, 2017 at 23:22
2
\$\begingroup\$

Eukleides, 17 bytes

Program:

a=centroid(empty)

Error:

X:1: empty set.

(Plus a newline). All fatal errors in Eukleides begin with (filename):(line number): and end with a period and a newline. I combed the source, and found that empty set was the shortest error. At first, I thought I was out of luck, because I only saw the lengthy command isobarycenter throwing it, but spotted centroid throwing it as well. Then I couldn't figure out how to make an empty set; all my attempts got me a syntax error first. Turns out, empty is a constant for an empty set, something I never needed to know before. I am quite confident this is the shortest Eukleides solution.

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

PHP, 56 bytes

<?php aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

produces

PHP Parse error:  syntax error, unexpected end of file
\$\endgroup\$
3
  • \$\begingroup\$ Actually, the code would have to be two bytes longer: the error message must be shorter than the code - and it includes a trailing newline. ;) \$\endgroup\$
    – Titus
    Oct 24, 2017 at 16:40
  • \$\begingroup\$ @Titus in fact, there was one a missing, since the Error msg has 55 bytes. Feel free to mess with DOS/Windows CRLF, I am using Linux. And no, the error msg does not include a newline, as it is usally followed by in /path/to/file.php or in Command line code... \$\endgroup\$ Oct 25, 2017 at 8:23
  • \$\begingroup\$ point. Why do I remember a leading newline now? I´m confusing myself. \$\endgroup\$
    – Titus
    Oct 25, 2017 at 11:43
2
\$\begingroup\$

Octave, 28 bytes

a=[];'Will cause error';a(1)

Try it online!

This throws this error:

error: a(1): out of bound 0

Damn, golfing error messages was cumbersome! I have rewritten this answer 8 times now, since I've gradually found error messages that were one byte shorter than the previous one. I think this answer took me an hour, since I've made a complete rewrite 8 times... :(


Why is this the shortest error message?

  • Relying on undefined functions or variables is not short enough (41)

     error: 'a' undefined near line 1 column 1
    
  • Relying on the wrong input type is not short enough (38)

    error: mod: wrong type argument 'sq_string'
    error: whos: all arguments must be strings
    error: sum: wrong type argument 'cell'
    
  • Relying on syntax errors is definitely not short enough (42)

    parse error:
    
      syntax error
    
    >>> &
        ^
    
  • Wrong indexing is not short enough (38)

    error: scalar cannot be indexed with {
    
  • Short function names and inputs that cause errors is not short enough (34)

    error: a: No such file or directory
    error: load: unable to find file a
    

I've looked through all the functions in Octave, and I can't imagine anything being shorter than this.

\$\endgroup\$
1
  • \$\begingroup\$ In MATLAB this would give a 33 byte error message (Index exceeds matrix dimensions.\n ). Still, beats mine by 9 bytes. \$\endgroup\$ Nov 9, 2017 at 14:33
2
\$\begingroup\$

Japt, 22 bytes

Dusting off the golfing cobwebs after a week's holidays; there's probably a shorter solution.

888888888888888888888z

Error:

No such function: N.z

Test it

\$\endgroup\$
2
  • \$\begingroup\$ Another reminder that I probably shouldn't still be using alert for errors :P \$\endgroup\$ Jul 21, 2017 at 20:48
  • \$\begingroup\$ @ETHproductions: if it wasn't for the intrusive alert, I probably wouldn't have remembered that error existed! \$\endgroup\$
    – Shaggy
    Jul 21, 2017 at 20:50
2
\$\begingroup\$

Shakespeare Programming Language, 73 bytes

Errors.
Ajax, the web technology.
Act XLII:;.
Scene LXIX:;.
Ajax:You cat.

Try it online!

Error message, 72 bytes

Runtime error at line 7: Ajax is not on stage, and thus cannot speak!

with one leading and two trailing newlines. Not sure whether the newlines count.

\$\endgroup\$
2
  • \$\begingroup\$ The ! in the first line messes up the debug a bit \$\endgroup\$
    – Jo King
    Jun 27, 2018 at 0:20
  • \$\begingroup\$ @JoKing Fixed, I believe. \$\endgroup\$
    – Maya
    Jun 27, 2018 at 17:49
2
\$\begingroup\$

@, 29 bytes

Error: Unknown instruction E!

This tries to call the function E, which does not exist.

Output message:

Error: Unknown instruction E
\$\endgroup\$
2
  • \$\begingroup\$ I don't think the error is 'smaller than the program itself' \$\endgroup\$
    – EdgyNerd
    Aug 10, 2019 at 18:35
  • \$\begingroup\$ I switched the language. (Introducing the @ language) \$\endgroup\$
    – user85052
    Aug 11, 2019 at 2:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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