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

106 Answers 106

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.

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

BASIC (BBC micro) 9 bytes

>REN 9,-5
Silly.
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Python 3, 71 bytes

a=b=c=d=e=f=g=h=i=j=k=l=m=n=o=p=q=r=s=t=u=v=w=x=y=z=A=B=C=D=E=F=1#
is=0

Try it online!

  File ".code.tio", line 2
    is=0
     ^
SyntaxError: invalid syntax
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ You can use a one char file name (TIO ... why) \$\endgroup\$ – Zacharý Jul 21 '17 at 19:55
  • \$\begingroup\$ @Zacharý /shrug not the shortest anyway, so I might as well make it consistent with TIO to avoid people asking me about the weird difference. I don't really care about bytecount lol \$\endgroup\$ – HyperNeutrino Jul 21 '17 at 20:06
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.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

J, 10 bytes

0000000^.0

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

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Lua, 45 bytes

0/###########################################

Try it online!

Error message, 44 bytes

lua: .code.tio:1: unexpected symbol near '0'
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You can use a one char file name! \$\endgroup\$ – Zacharý Jul 21 '17 at 19:53
  • \$\begingroup\$ I think its better that officialaimm didn't. Beat my example by 1. :P \$\endgroup\$ – user72528 Jul 21 '17 at 19:55
  • \$\begingroup\$ How is it better that he didn't? \$\endgroup\$ – Zacharý Jul 21 '17 at 19:56
  • 1
    \$\begingroup\$ It's not a better result, I just found it more funny that he beat the example by exactly 1 byte. \$\endgroup\$ – user72528 Jul 21 '17 at 19:59
  • \$\begingroup\$ That would be because I had forgotten the example was in Lua and I don't really know lua... :D \$\endgroup\$ – officialaimm Jul 22 '17 at 4:05
2
\$\begingroup\$

Japt, 32 bytes

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

Error message (31 bytes):

SyntaxError: Unexpected token ?

Try it online!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

2Col, 50 bytes

Invalid code!
Line 0 contains invalid 2Col code!
1

Try it on 2ColIDE

Outputs:

Invalid code!
Line 0 contains invalid 2Col code!

With a trailing newline.

Explanation

2Col only really has 1 error, and it's caused by the structure of the code being wrong. 2Col expects every line to be exactly 2 characters long, so if a line is longer or shorter than that, you get the above error.

Given that for this challenge the code must be longer than the error, the easiest way to achieve that is to use the error itself and add a byte.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Mathematica, 120 bytes

"Take it easy my brother JungHwan Min,Take it easy my brother LegionMammal978,Take it easy my brother Charlie"*666*666/0

error-> Power::infy: Infinite expression 1/0 encountered.

see comments for details...

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Your program has to be longer; the exact error message is Power::infy: Infinite expression 1/0 encountered. (on Mathematica Kernel or Mathematica REPL 10.3 and before. The error is Power: Infinite expression 1/0 encountered. on Mathematica REPL 11 and onwards) \$\endgroup\$ – JungHwan Min Jul 22 '17 at 3:05
  • \$\begingroup\$ And the above two error messages ignore the FractionBox; it's up to the OP to decide whether the FractionBox component has to be implemented. \$\endgroup\$ – JungHwan Min Jul 22 '17 at 3:11
  • \$\begingroup\$ I asked the question here: codegolf.stackexchange.com/questions/133840/… \$\endgroup\$ – JungHwan Min Jul 22 '17 at 3:18
  • 1
    \$\begingroup\$ @LegionMammal978 Are you going to measure JungHwan's answer, too, (?) or this is just about my answer? \$\endgroup\$ – J42161217 Jul 22 '17 at 12:59
  • 2
    \$\begingroup\$ yes, it is quite funny! posting all these things on the main chat and doing exactly the same! \$\endgroup\$ – J42161217 Jul 22 '17 at 13:25
2
\$\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 -------------

| improve this answer | |
\$\endgroup\$
2
\$\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.

| improve this answer | |
\$\endgroup\$
2
\$\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.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

GW-Basic, 9 bytes

Enter:

?&H100000

This will yield the following error message:

Overflow

I believe this is the shortest error message in GW-Basic. The reason I used a hexadecimal constant is that while GW-Basic doesn't support long integers, it does support single and double(!) precision floating point numbers.

| improve this answer | |
\$\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
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

LibreOffice Calc, 7 bytes

=aaaaaa

Result:

#NAME?
| improve this answer | |
\$\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.

| improve this answer | |
\$\endgroup\$
  • \$\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 '17 at 16:46
  • 1
    \$\begingroup\$ @TehPers that sounds like a sufficiently different approach that you could make it an answer. \$\endgroup\$ – CompuChip Jul 27 '17 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
| improve this answer | |
\$\endgroup\$
2
\$\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.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\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 '17 at 2:19
2
\$\begingroup\$

Batch 90 18 bytes

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

Missing Operand\ Golfed by SteveFest

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This shold work: @set/ab=1+2+345) - Missing Operand \$\endgroup\$ – stevefestl Jul 27 '17 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 '17 at 5:06
  • 1
    \$\begingroup\$ @SteveFest that is fine XD \$\endgroup\$ – Christopher Jul 29 '17 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.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

PHP, 56 bytes

<?php aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

produces

PHP Parse error:  syntax error, unexpected end of file
| improve this answer | |
\$\endgroup\$
  • \$\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 '17 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\$ – rexkogitans Oct 25 '17 at 8:23
  • \$\begingroup\$ point. Why do I remember a leading newline now? I´m confusing myself. \$\endgroup\$ – Titus Oct 25 '17 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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ In MATLAB this would give a 33 byte error message (Index exceeds matrix dimensions.\n ). Still, beats mine by 9 bytes. \$\endgroup\$ – Tom Carpenter Nov 9 '17 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

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Another reminder that I probably shouldn't still be using alert for errors :P \$\endgroup\$ – ETHproductions Jul 21 '17 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 '17 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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ The ! in the first line messes up the debug a bit \$\endgroup\$ – Jo King Jun 27 '18 at 0:20
  • \$\begingroup\$ @JoKing Fixed, I believe. \$\endgroup\$ – NieDzejkob Jun 27 '18 at 17:49
2
\$\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).

| improve this answer | |
\$\endgroup\$
2
\$\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.

| improve this answer | |
\$\endgroup\$
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
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I don't think the error is 'smaller than the program itself' \$\endgroup\$ – EdgyNerd Aug 10 '19 at 18:35
  • \$\begingroup\$ I switched the language. (Introducing the @ language) \$\endgroup\$ – user85052 Aug 11 '19 at 2:04
2
\$\begingroup\$

05AB1E, 410 bytes

ι                                                                                                                                                                                                                                                                                                                                                                                                                         

Try it online!

Error, 409 bytes

** (RuntimeError) Could not convert  to integer.
    (osabie) lib/interp/functions.ex:101: Interp.Functions.to_integer!/1
    (osabie) lib/interp/commands/special_interp.ex:113: Interp.SpecialInterp.interp_step/3
    (osabie) lib/interp/interpreter.ex:127: Interp.Interpretr.interp/3
    (osabie) lib/osabie.ex:62: Osabie.CLI.main/1
    (elixir) lib/kernel/cli.ex:105: anonymous fn/3 in Kernel.CLI.exec_fun/2
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Red, 29 Bytes

a/1/1/1/1/1/1/1/1/1/1/1/1/1/1
Script Error: a has no value
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! I fixed the formatting, you can revert it if you preferred the original. \$\endgroup\$ – Redwolf Programs Nov 17 at 21:35
1
\$\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.

| improve this answer | |
\$\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.