Shortest Error Message

136

7

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 '['

user72528

Posted 2017-07-21T19:00:48.293

Reputation: 1 383

Comments are not for extended discussion; this conversation has been moved to chat.

– Dennis – 2017-07-28T16:18:05.433

1@Dennis I guess that's one way of solving the "OP doesn't edit clarifications into question" problem. – Ørjan Johansen – 2017-07-29T23:52:26.543

1

Thanks for accepting my answer, which got the most votes; however, this was tagged [tag:code-golf], so you should accept this answer, which is the shortest.

– MD XF – 2017-11-24T21:38:27.170

@smartpeople is this: "__main__.CodeException: Raised an &rror." my error or is this:"Raised an &rror." – FantaC – 2017-12-25T17:13:09.410

TrumpScript running in China? – Stan Strum – 2018-01-30T06:34:43.807

Is an input allowed (adding the used input to the byte-count of course)? I could save a couple bytes by taking a one-char input and trying to parse it as a number. – Kevin Cruijssen – 2018-06-29T11:52:41.093

Answers

58

ed, 3 bytes

Note: Most of the answers here are ignoring the trailing newline printed as part of the error message in their count. But I don’t see anything in the question to justify ignoring it, and the author commented that the newline should be included. So unless the question is changed, I’m going to include it.

Code (with trailing newline):

??

Error (with trailing newline):

?

Anders Kaseorg

Posted 2017-07-21T19:00:48.293

Reputation: 29 242

19Actually, this is impossible to beat. :P – totallyhuman – 2017-07-21T20:21:28.300

Not entirely, if for some reason the newline alone counts as an error, or if there exists an error that is one character long and does not have a trailing new line, then it's possible. – Zacharý – 2017-07-21T20:24:21.693

1Can ed do addition and primality testing? Or is that not required for this type of challenge? – Stephen – 2017-07-21T22:34:17.107

4@StepHen Yes, it can do addition and primality testing in unary via the usual regex-with-backreferences trick. – Anders Kaseorg – 2017-07-22T00:57:23.197

well, you got my upvote :D – Atmahadli – 2017-07-25T07:48:42.853

This answer was exactly my first thought on reading the question. Ed is justly famed for its succinct error messages. – Toby Speight – 2017-07-26T10:52:53.733

1Very clever, but '?' isn't fatal. – Mark Plotnick – 2017-07-27T11:50:56.397

If the error isn't fatal as Mark points out, I'm afraid this answer is invalid. Please edit the answer if there's an ed implementation where the error actually terminates the program, and flag it for moderator attention so that it can be undeleted. – Martin Ender – 2018-02-20T08:31:08.623

2

As pointed out in a flag, the error is fatal if the code isn't read from a terminal. Try it online!

– Dennis – 2018-07-04T14:12:56.023

59

C (modern Linux), 19 bytes

Would've done my famous segfault but totallyhuman stole it.

main(){longjmp(0);}

Output (18 bytes):

Segmentation fault

MD XF

Posted 2017-07-21T19:00:48.293

Reputation: 11 605

You currently have a higher score than me so... Win-win? – totallyhuman – 2017-07-21T20:23:15.387

1

Let us continue this discussion in chat.

– Dennis – 2017-07-21T21:48:36.337

Are there no other locale with a shorter version (So that you could then use main(){main();})? – 12431234123412341234123 – 2017-07-27T13:10:48.223

@12431234123412341234123 Not that I know of. Also, main(){main();} is not guaranteed to seg-fault. – MD XF – 2017-07-30T20:51:43.290

1@MDXF There is no guarantee (and with optimization enabled in gcc or clang, it end up in a endless loop or ignore the call). But on Code Golf we need a working implementation not a guarantee. – 12431234123412341234123 – 2017-07-31T09:08:16.863

48

Python 2, 35 bytes

import sys;sys.tracebacklimit=000;a

Gives error:

NameError: name 'a' is not defined

orlp

Posted 2017-07-21T19:00:48.293

Reputation: 37 067

14modifying the traceback limit... nice one – HyperNeutrino – 2017-07-21T19:44:47.490

1This is clever! – Skyler – 2017-07-24T19:37:29.913

34

JavaScript (Firefox), 31 bytes

# This is a comment, right? ...

Throws this error:

SyntaxError: illegal character

Tested in the console of Firefox 54.0.1 on Windows 7.

ETHproductions

Posted 2017-07-21T19:00:48.293

Reputation: 47 880

26

Python 2, 87 79 bytes

-8 bytes thanks to Zacharý and Erik the Outgolfer.

from __future__ import braces
#i am most surely seriously actually totallyhuman

Try it online!

Error message, 78 bytes:

Assuming the code is stored in a file named a.

  File "a", line 1
    from __future__ import braces
SyntaxError: not a chance

This is actually a nice little Easter egg in Python. :D

totallyhuman

Posted 2017-07-21T19:00:48.293

Reputation: 15 378

1You can assume a one-char file name! – Zacharý – 2017-07-21T19:28:20.680

1

Assuming a 1-char file name, you can golf to this.

– Erik the Outgolfer – 2017-07-21T19:36:25.413

Heh, nice. - - - – totallyhuman – 2017-07-21T19:40:36.247

1But the error message has to be smaller than the program itself... – Leaky Nun – 2017-07-21T20:06:42.850

@LeakyNun Fixed. – totallyhuman – 2017-07-21T20:09:43.803

1If you use IDLE you can get \s\sFile "<stdin>", line 1\nSyntaxError: not a chance which is only 50 bytes [\s is a space and \n is a newline], so you can get a 51 byte program.. – boboquack – 2017-07-26T08:39:54.523

20

Haskell, 13 bytes

main = (main)

Save as t.hs or another one-character name, compile with ghc, and run. Error message (with trailing newline):

t: <<loop>>

Anders Kaseorg

Posted 2017-07-21T19:00:48.293

Reputation: 29 242

19

Taxi, 38 21 bytes

Switch to plan "abc".

Produces:

error: no such label

Try it online!

-17 bytes thanks to Engineer Toast

Tries to switch to "abc", which does not exist. You would have [abc] somewhere.

Stephen

Posted 2017-07-21T19:00:48.293

Reputation: 12 293

4You can get down to 21 bytes with Switch to plan "abc". producing error: no such label. This might be one of the few [tag:code-golf] challenges where Taxi beats some traditional languages. – Engineer Toast – 2017-07-21T20:00:01.993

@EngineerToast thanks, didn't think of that one. – Stephen – 2017-07-21T20:03:19.543

18

><>, 26 bytes

>>>>>>>>>>>>>>>>>>>>>>>>>:

Try it online!

Every error message in Fish is something smells fishy..., so this just moves the pointer right enough times to be longer than that and attempts to duplicate the top of the stack, which is empty at the time.

HyperNeutrino

Posted 2017-07-21T19:00:48.293

Reputation: 26 575

2I like it, and it's definately the most fishy of all solutions :-) – Xan-Kun Clark-Davis – 2017-07-25T16:58:52.677

@Xan-KunClark-Davis sigh you had to... :P – HyperNeutrino – 2017-07-25T17:26:17.823

18

JavaScript (Firefox), 21 bytes

(a=null)=>a.charAt(1)

Error (20 bytes): TypeError: a is null

Oliver

Posted 2017-07-21T19:00:48.293

Reputation: 7 160

2D'oh! I knew there was a shorter one... – ETHproductions – 2017-07-21T20:49:04.080

I had the same idea, came up with a=null;a.x01234567890

Same amount of bytes – RuteNL – 2017-11-09T13:43:56.663

16

System V shell, 25 bytes

mount /dev/hda1 /mnt/hda1

Error message (23 bytes):

mount: not a typewriter

"Not a typewriter" or ENOTTY is an error code defined in errno.h on Unix systems. This is used to indicate that an invalid ioctl (input/output control) number was specified in an ioctl system call. On my system, in /usr/include/asm-generic/errno-base.h, I can find this line:

#define ENOTTY          25      /* Not a typewriter */

In Version 6 UNIX and older, I/O was limited to serial-connected terminal devices, such as a teletype (TTY). These were usually managed through the gtty and stty system calls. If one were to try to use either of these system calls on a non-terminal device, ENOTTY was generated.

Nowadays, there is naturally no need to use a teletype. When gtty and stty were replaced with ioctl, ENOTTY was kept. Some systems still display this message; but most say "inappropriate ioctl for device" instead.

MD XF

Posted 2017-07-21T19:00:48.293

Reputation: 11 605

Please explain... – Mega Man – 2017-07-22T17:05:03.050

@MegaMan Updated with explanation. – MD XF – 2017-07-22T17:46:33.000

1Upvote for actually enlightening explanation. – Xan-Kun Clark-Davis – 2017-07-25T17:00:02.570

11

QBasic, 11 bytes

There are two solutions of 11 bytes in QBasic, one of which might be golfed further. The shortest error message QBasic has is overflow, and can be triggered as such:

i%=i%+32677

This throws overflow because the max for an integer (i%) is 32676. I couldn't get the 32677 golfed without QBasic auto-casting this to long...

Another error, at 11 bytes, would be out of data. QBasic has DATA statements that store data in the program, which can later be accessed by READ statements. Issuing more READs than DATAs causes the error:

READ a$ '--

Note that the statement is padded with a comment to get it up to the length of the error message. Yes, I have an error message with a shorter program, and a program with a shorter error message ...

steenbergh

Posted 2017-07-21T19:00:48.293

Reputation: 7 772

11

C (Modern Linux), 19 bytes

I suggested this in chat, but nobody took the oppurtunity. :P Credit to MD XF's hilarious answer.

main(){puts('s');;}

Error message, 18 bytes

Segmentation fault

totallyhuman

Posted 2017-07-21T19:00:48.293

Reputation: 15 378

1But the error message has to be smaller than the program itself... – Leaky Nun – 2017-07-21T20:08:54.390

Byte counts were screwed up, my bad. – totallyhuman – 2017-07-21T20:16:26.553

9This is a generic message printed by the shell when subprocess terminates with exit code 139. The C program itself produces no error message at all. – Dennis – 2017-07-21T21:41:38.580

@totallyhuman DV was mine, forgot to reverse it after we cleared up the issue. – MD XF – 2017-07-21T22:36:43.913

7@Dennis Exit code 139 is actually another lie made up by the shell. Unix distinguishes between signal 11 (W_EXITCODE(0, 11) == 11) and exit code 139 (W_EXITCODE(139, 9) == 139 << 8). Shells set $? non-surjectively to WIFEXITED(wstatus) ? WEXITSTATUS(wstatus) : WTERMSIG(wstatus) + 128, but most languages expose the difference. – Anders Kaseorg – 2017-07-22T18:05:35.057

2@Anders Is WIFEXITED(wstatus) equivalent to DIVORCE(alimony) by any chance? – Janus Bahs Jacquet – 2017-07-27T10:50:53.547

11

Javascript (V8), 24 bytes

decodeURIComponent('%');

Error, 23 bytes:

URIError: URI malformed

Tested on Nodejs v6.11.0 and Google Chrome v59.0.3071.115.

Try it online!

Note that TIO expands the error message.

Max Sinev

Posted 2017-07-21T19:00:48.293

Reputation: 211

5Welcome to PPCG! – Stephen – 2017-07-24T13:02:51.823

11

TrumpScript, 30 bytes

We love NATO!
America is great

Error message:

Trump doesn't want to hear it

Timtech

Posted 2017-07-21T19:00:48.293

Reputation: 12 038

3

P.S. Error codes are in constants.py

– Timtech – 2017-07-26T12:52:39.317

10

PowerShell, 215 189 bytes

[]
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

Try it online!

So, PowerShell has ... verbose ... error messages. Additionally, most non-syntax error messages are Runtime Exceptions, meaning that they're non-fatal, which reduces this problem to needing to find a short parsing error.

I think this is one of the shortest, if not the shortest, @TessellatingHeckler has demonstrated this is the shortest parsing error, and it still weighs in at 188 bytes just for the error message. So we basically need to append enough 1s to reach 189 bytes of "code."

Running this locally on c:\a.ps1 for example, will cut down on the byte count by a handful as it's just a shorter file path, but then it's not available on TIO.

Produces error:

At /tmp/home/.code.tio.ps1:1 char:2
+ []
+  ~
Missing type name after '['.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingTypename

AdmBorkBork

Posted 2017-07-21T19:00:48.293

Reputation: 41 581

I was asked three questions in the comments, one of which you asked, but the two you didn't ask both applied to your answer, and not yours. – user72528 – 2017-07-21T19:37:31.047

@user72528 Yeah, I found that amusing as well. – AdmBorkBork – 2017-07-21T19:38:36.933

You can use a one char file name! – Zacharý – 2017-07-21T19:54:52.560

1@Zacharý I can, but then it's not reproducible on TIO due to how TIO handles the sandboxing. I prefer to keep it usable on TIO than to save a few bytes. – AdmBorkBork – 2017-07-21T20:00:11.080

That's fine (the ! wasn't needed), since this definitely won't be winning anything. – Zacharý – 2017-07-21T20:02:17.913

2

What about [] which looks like a shorter error Missing type name after '[' and depending on exactly how you count could be around 190 - https://tio.run/##K8gvTy0qzkjNyfn/PzqWy3Dogv//AQ (taken from the parser strings here that looks like the shortest parser error to me ([xml](gc .\ParserStrings.resx)).root.data.value | sort { $_.length } -Desc).

– TessellatingHeckler – 2017-07-21T21:34:06.700

@TessellatingHeckler Nice job polling the code to find a shorter error message. Thanks! – AdmBorkBork – 2017-07-24T12:50:19.980

9

Commodore 64 Basic, 15 bytes

?SYNTAX   ERROR

Produces

?SYNTAX  ERROR

(Note two spaces in the error message, where the program has three)

?SYNTAX ERROR is tied with ?VERIFY ERROR as the third-shortest error message that C64 Basic can produce, and the shortest that can be reliably triggered by code (the shortest message, BREAK IN 1, requires user interaction, while ?LOAD ERROR requires a defective tape or floppy disk, and ?VERIFY ERROR requires the presence of a floppy or tape containing a file that doesn't match the program in RAM).

Mark

Posted 2017-07-21T19:00:48.293

Reputation: 2 099

1

Ha, didn't even see this when I posted mine. Always good to see another BASIC user... +1

– MD XF – 2017-07-23T00:51:17.410

8

R, 29 28 bytes

-1 byte thanks to JarkoDubbeldam

a #abcdefghijklmnopqrstuvwxy

Throws the error Error: object 'a' not foundwhich is 27 bytes.

Try it online!

Giuseppe

Posted 2017-07-21T19:00:48.293

Reputation: 21 077

2a #abcdefghijklmnopqrstuvwxy's error Error: object 'a' not found is one byte shorter. – JAD – 2017-07-23T15:16:23.430

@JarkoDubbeldam thank you. – Giuseppe – 2017-07-25T17:45:50.010

7

Ruby (33 32 bytes)

32 bytes

&
#abcdefghijklmnopqrstuvwxyz12

Throws the error (assuming in a file named "a"):

31 bytes

a:1: syntax error, unexpected &

Edit: Shaved a byte off by using & instead of << thanks to Eric, who also came up with an even shorter Ruby solution: http://codegolf.stackexchange.com/a/135087/65905

ameketa

Posted 2017-07-21T19:00:48.293

Reputation: 71

1Welcome to PPCG! – Martin Ender – 2017-07-21T19:56:34.780

@EricDuminil nice! I thought all the single character operators were quoted in the error message, but you're right: & isn't. Neat! Also, good find with the hex escape. I was struggling to find a shorter and non-stack-trace fatal error message other than a syntax error. – ameketa – 2017-07-23T19:53:03.267

@ameketa: I actually wrote a bruteforce program and tested every possible 1, 2 and 3-byte Ruby program :D Thanks for the link. – Eric Duminil – 2017-07-23T20:50:27.763

5

Brainf**k, 17 bytes, this interpreter

+++++++++++++++<<

Brainf**k is such a simple language that almost every interpreter has a different error message. This one uses Memory Error: -1 for when the pointer is moved to the left too much and you attempt another operation

HyperNeutrino

Posted 2017-07-21T19:00:48.293

Reputation: 26 575

I guess choosing an interpreter is as much a part of the challenge as choosing a language. – user72528 – 2017-07-21T19:18:34.487

@user72528 Well here, we define a language by its interpreter, so this challenge is a bit about choosing the interpreter with the shortest error messages :) – HyperNeutrino – 2017-07-21T19:21:37.967

1Who beats brainfuck? Nobody? Alright. – Erik the Outgolfer – 2017-07-21T19:28:47.687

The unbeatable solution would a two byte solution which causes an error of 1 character. – Zacharý – 2017-07-21T19:30:03.067

@Zacharý Certainly lol – HyperNeutrino – 2017-07-21T19:44:29.153

weird interpreter; wraps calls value but not cells layout – Uriel – 2017-07-22T21:18:46.023

@Uriel It is quite weird. Of course, I'm abusing that just because it exists :) – HyperNeutrino – 2017-07-22T21:19:14.797

The reasonable thing for brainfuck is to support an infinite number of cells of infinite value on both sides. – pppery – 2017-08-16T22:26:44.760

5

Common Lisp, 20 bytes

(/ 1 0))))))))))))))

Try it online!

Error Message

/: division by zero

Cheldon

Posted 2017-07-21T19:00:48.293

Reputation: 91

11o_o unbalanced parentheses in Lisp ... you learn something new every day. – Zacharý – 2017-07-21T19:32:18.253

1If you replace the 0 with 1, it will error on the parens but it doesn't get that far with 0. I just needed to add characters to be longer than the message – Cheldon – 2017-07-21T19:34:54.733

5

TryAPL, 11 bytes

Code (11):

'abcdefghij

Error (10):

open quote

Zacharý

Posted 2017-07-21T19:00:48.293

Reputation: 5 710

5

Javascript(Firefox),29 27 bytes

new Date('-').toISOString()

throws RangeError: invalid date which is 24 bytes. Tested on Firefox 54.0.1 on Windows 10.

SuperStormer

Posted 2017-07-21T19:00:48.293

Reputation: 927

5

ZX Spectrum Basic, 9 bytes

RUN USR 8

produces:

Error message

Explanation:

I am (exceptionally) counting ASCII representation of the program for length purposes, including the end of line (it's not really important, since we could always pad a shorter program with spaces).

Usually, ZX Spectrum error messages are longer and more helpful than this - the ROM routine at 0x0008 expects error code following the machine code call to RST 8., and fetches some random (deterministic) byte from the ROM, which produces this nonsensical error message M. 5 is the error number, , is added by the error printing routine and 0:1 is the line:command position of the error.

Radovan Garabík

Posted 2017-07-21T19:00:48.293

Reputation: 437

Actually this is 9 bytes normally anyway, because the ZX Spectrum doesn't evaluate numbers at run time, so there are actually 6 hidden bytes which allow it to access the binary representation of 8 directly. – Neil – 2017-07-23T19:11:42.963

4

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!

programmer5000

Posted 2017-07-21T19:00:48.293

Reputation: 7 828

4

Perl 5, 5 bytes

die$/

Outputs a newline, for one byte.

Try it online!

aschepler

Posted 2017-07-21T19:00:48.293

Reputation: 717

._. Now ... if only perl errors on the empty file! – Zacharý – 2017-07-22T01:34:36.617

4Wait, is this a violation of the "may not be generated by the program itself"? I didn't understand what that rule was saying. – aschepler – 2017-07-22T01:41:16.630

1@Zacharý ... giving an error message with total length negative one? – aschepler – 2017-07-22T01:54:15.060

1This might be invalid ... or not, depends on whether the OP meant the error or the error message – Zacharý – 2017-07-22T02:14:47.903

^ clarification: whether a program errors directly or creates an error message directly – Zacharý – 2017-07-23T00:31:03.073

4

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)

Timtech

Posted 2017-07-21T19:00:48.293

Reputation: 12 038

4

Perl 5, 11 bytes

Since I'm not clear on whether my other answer obeys the challenge rules, here's another alternative.

#line 0
die

Error output:

Died.

With an ending newline, for 6 bytes.

Try it online!

For some reason the Perl interpreter internal function Perl_mess_sv contains:

if (CopLINE(cop))
    Perl_sv_catpvf(aTHX_ sv, " at %s line %" IVdf,
                    OutCopFILE(cop), (IV)CopLINE(cop));

where CopLINE(cop) gets the current code context's line number. So if that line number happens to evaluate to zero, Perl skips adding the usual " at <filename> line <n>" to the error message.

aschepler

Posted 2017-07-21T19:00:48.293

Reputation: 717

1It seems nor valid to me. IIRC die is for the program to exit. – sergiol – 2017-07-22T17:34:59.847

1How is that any different than python raise? – Eric Duminil – 2017-07-23T12:09:13.410

Well, the OP might have been referring to either generating the error or the error message. I commented on which one he meant. – Zacharý – 2017-07-23T14:42:12.923

4

ArnoldC, 150 bytes

IT'S SHOWTIME
HEY CHRISTMAS TREE b
YOU SET US UP 0
GET TO THE CHOPPER b
HERE IS MY INVITATION b
HE HAD TO SPLIT 0
ENOUGH TALK
YOU HAVE BEEN TERMINATED

Try it online!

Error is 94 bytes (including trailing newline):

Exception in thread "main" java.lang.ArithmeticException: / by zero
    at code.main(Hello.java)

Preserved because I think this is more funny - spoiler: it was those dang teenage pranksters.

ArnoldC, 280 bytes

IT'S SHOWTIME
HEY CHRISTMAS TREE BRBDoorBetterNotBeThosePeskyTeenagePranksters
YOU SET US UP 0
GET YOUR ASS TO MARS BRBDoorBetterNotBeThosePeskyTeenagePranksters
DO IT NOW
I WANT TO ASK YOU A BUNCH OF QUESTIONS AND I WANT TO HAVE THEM ANSWERED IMMEDIATELY
YOU HAVE BEEN TERMINATED

Pseudocode:

start program
new variable
set to 0
set new variable to output from function
call function
take input
end program

Try it online!

Generates a "no input" error. (Almost all other errors in ArnoldC include a large piece of boilerplate):

279 bytes (including trailing newline):

Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Scanner.java:862)
    at java.util.Scanner.next(Scanner.java:1485)
    at java.util.Scanner.nextInt(Scanner.java:2117)
    at java.util.Scanner.nextInt(Scanner.java:2076)
    at code.main(Hello.java)

TemporalWolf

Posted 2017-07-21T19:00:48.293

Reputation: 241

3

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.

Eric Duminil

Posted 2017-07-21T19:00:48.293

Reputation: 701

I think you should separate your answers. – Solomon Ucko – 2017-07-24T00:51:15.230

@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. – Eric Duminil – 2017-07-24T07:34:24.990

Actually, I'm not sure why I said that, so nevermind. – Solomon Ucko – 2017-07-30T14:00:56.797

3

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.

fluffy

Posted 2017-07-21T19:00:48.293

Reputation: 725

3

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.

jochen

Posted 2017-07-21T19:00:48.293

Reputation: 131

3

BASIC (BBC micro) 9 bytes

>REN 9,-5
Silly.

Baldrickk

Posted 2017-07-21T19:00:48.293

Reputation: 311

2

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

HyperNeutrino

Posted 2017-07-21T19:00:48.293

Reputation: 26 575

1You can use a one char file name (TIO ... why) – Zacharý – 2017-07-21T19:55:45.523

@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 – HyperNeutrino – 2017-07-21T20:06:28.703

2

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.

James

Posted 2017-07-21T19:00:48.293

Reputation: 54 537

Same byte count different approach – Post Rock Garf Hunter – 2017-07-21T19:55:59.377

2

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

J42161217

Posted 2017-07-21T19:00:48.293

Reputation: 15 931

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) – JungHwan Min – 2017-07-22T03:05:41.173

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. – JungHwan Min – 2017-07-22T03:11:33.133

I asked the question here: https://codegolf.stackexchange.com/questions/133840/shortest-error-message#comment330079_133840

– JungHwan Min – 2017-07-22T03:18:21.953

@JungHwanMin Actually, there is an exact textual form for the error: These exact bytes are output to STDOUT when running this program as a script using version 10.1.0.0 of the kernel. The message is precisely 119 bytes long, as measured by wc -c; thus, this program would have to be at least 120 bytes long to satisfy the challenge requirements.

– LegionMammal978 – 2017-07-22T11:22:09.230

1@LegionMammal978 Are you going to measure JungHwan's answer, too, (?) or this is just about my answer? – J42161217 – 2017-07-22T12:59:11.863

@Jenny_mathy Mostly about your answer, I didn't know that JungHuan answered. – LegionMammal978 – 2017-07-22T13:17:57.777

2yes, it is quite funny! posting all these things on the main chat and doing exactly the same! – J42161217 – 2017-07-22T13:25:27.017

@Jenny_mathy welp, I copy/pasted the error message from the Mathematica REPL. My error didn't really contain FractionBox or anything, which yours does. And yes, it is quite funny that you assumed I made the same mistake. – JungHwan Min – 2017-07-22T21:44:08.017

Edited version is very nice. 5/7 perfect score. – TemporalWolf – 2017-07-26T17:22:59.393

2

J, 10 bytes

0000000^.0

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

Richard Donovan

Posted 2017-07-21T19:00:48.293

Reputation: 87

2

Lua, 45 bytes

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

Try it online!

Error message, 44 bytes

lua: .code.tio:1: unexpected symbol near '0'

officialaimm

Posted 2017-07-21T19:00:48.293

Reputation: 2 739

You can use a one char file name! – Zacharý – 2017-07-21T19:53:53.963

I think its better that officialaimm didn't. Beat my example by 1. :P – user72528 – 2017-07-21T19:55:36.710

How is it better that he didn't? – Zacharý – 2017-07-21T19:56:50.870

1It's not a better result, I just found it more funny that he beat the example by exactly 1 byte. – user72528 – 2017-07-21T19:59:00.133

That would be because I had forgotten the example was in Lua and I don't really know lua... :D – officialaimm – 2017-07-22T04:05:08.267

2

Japt, 32 bytes

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

Error message (31 bytes):

SyntaxError: Unexpected token ?

Try it online!

Oliver

Posted 2017-07-21T19:00:48.293

Reputation: 7 160

2

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

Shaggy

Posted 2017-07-21T19:00:48.293

Reputation: 24 623

Another reminder that I probably shouldn't still be using alert for errors :P – ETHproductions – 2017-07-21T20:48:28.070

@ETHproductions: if it wasn't for the intrusive alert, I probably wouldn't have remembered that error existed! – Shaggy – 2017-07-21T20:50:13.467

2

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.

Skidsdev

Posted 2017-07-21T19:00:48.293

Reputation: 9 656

2

PHP, 56 bytes

<?php aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

produces

PHP Parse error:  syntax error, unexpected end of file

rexkogitans

Posted 2017-07-21T19:00:48.293

Reputation: 589

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. ;) – Titus – 2017-10-24T16:40:47.077

@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... – rexkogitans – 2017-10-25T08:23:05.887

point. Why do I remember a leading newline now? I´m confusing myself. – Titus – 2017-10-25T11:43:01.360

2

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 -------------

MD XF

Posted 2017-07-21T19:00:48.293

Reputation: 11 605

2

Batch 90 18 bytes

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

Missing Operand\ Golfed by SteveFest

Christopher

Posted 2017-07-21T19:00:48.293

Reputation: 3 428

This shold work: @set/ab=1+2+345) - Missing Operand – stevefestl – 2017-07-27T00:39:34.390

I was wrong: @set/ab=1+*2*3*4*5 - Missing Operator It's just as few bytes. I'm sorry :( – stevefestl – 2017-07-29T05:06:59.617

1@SteveFest that is fine XD – Christopher – 2017-07-29T23:22:38.017

2

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.

JoshRagem

Posted 2017-07-21T19:00:48.293

Reputation: 189

2

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.

Anonymous

Posted 2017-07-21T19:00:48.293

Reputation: 161

2

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.

Anonymous

Posted 2017-07-21T19:00:48.293

Reputation: 161

2

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

theblitz

Posted 2017-07-21T19:00:48.293

Reputation: 1 201

2

LibreOffice Calc, 7 bytes

=aaaaaa

Result:

#NAME?

tsh

Posted 2017-07-21T19:00:48.293

Reputation: 13 072

2

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.

TheLethalCoder

Posted 2017-07-21T19:00:48.293

Reputation: 6 930

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. – TehPers – 2017-07-26T16:46:48.677

1@TehPers that sounds like a sufficiently different approach that you could make it an answer. – CompuChip – 2017-07-27T07:04:11.980

2

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

Poke

Posted 2017-07-21T19:00:48.293

Reputation: 3 075

2

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.

NieDzejkob

Posted 2017-07-21T19:00:48.293

Reputation: 4 630

The ! in the first line messes up the debug a bit – Jo King – 2018-06-27T00:20:32.823

@JoKing Fixed, I believe. – NieDzejkob – 2018-06-27T17:49:03.540

2

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.

Joe

Posted 2017-07-21T19:00:48.293

Reputation: 895

1I 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). – brhfl – 2017-07-27T02:19:26.040

2

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.

brhfl

Posted 2017-07-21T19:00:48.293

Reputation: 1 291

2

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.

Stewie Griffin

Posted 2017-07-21T19:00:48.293

Reputation: 43 471

In MATLAB this would give a 33 byte error message (Index exceeds matrix dimensions.\n). Still, beats mine by 9 bytes. – Tom Carpenter – 2017-11-09T14:33:11.050

2

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.

Jo King

Posted 2017-07-21T19:00:48.293

Reputation: 38 234

2

@, 29 bytes

Error: Unknown instruction E!

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

Output message:

Error: Unknown instruction E

user85052

Posted 2017-07-21T19:00:48.293

Reputation:

I don't think the error is 'smaller than the program itself' – EdgyNerd – 2019-08-10T18:35:31.087

I switched the language. (Introducing the @ language) – None – 2019-08-11T02:04:21.813

1

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.

caird coinheringaahing

Posted 2017-07-21T19:00:48.293

Reputation: 13 702

1

Python 3, 67 bytes

`
  File ".code.tio", line 1
    ^`````
SyntaxError: invalid syntax

Try it online!

Error Message, 66 bytes

  File ".code.tio", line 1
    `
    ^
SyntaxError: invalid syntax

officialaimm

Posted 2017-07-21T19:00:48.293

Reputation: 2 739

3You can use a one char file name – Zacharý – 2017-07-21T19:55:03.703

Yeah, Thanks.... But to make it more TIO-interactive... if you know what I mean.. – officialaimm – 2017-07-22T04:06:23.377

1

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);

Ivan Botero

Posted 2017-07-21T19:00:48.293

Reputation: 301

The code must be at least one byte longer than the error message. – Zacharý – 2017-07-21T19:31:28.610

This is C++ code! – Zacharý – 2017-07-21T19:53:12.093

@Zacharý Oups! Thanks for the correction! – Ivan Botero – 2017-07-21T19:57:13.233

And ... you can use a one char file name. – Zacharý – 2017-07-21T19:58:17.443

Would this work? printf("%s", variable)=>printf("%s",variable)? – Zacharý – 2017-07-21T20:27:35.543

@Zachary polite request, would you mind commenting a bit less? Most posts on this challenge that you've commented multiple times on, your comments could've been condensed into one. The problem is that it pings the post author more times than is necessary and also wastes some space. Thanks :) – MD XF – 2017-07-23T22:14:51.353

I am sorry about that, I sometimes just realize things after I can't edit the comment anymore. I'll try to organize my thoughts/comments into one comment from now on. – Zacharý – 2017-07-24T00:01:36.257

1

Brain-Flak (BrainHack), 43 + 3 = 46 bytes

([()])()()()()()()()()()()()()()()()()()()-

Try it online!

Produces the error

BrainHack: Prelude.chr: bad argument: (-1)

Post Rock Garf Hunter

Posted 2017-07-21T19:00:48.293

Reputation: 55 382

1

Tcl/Tk, 19

pack [text .text 1]

outputs

18

unknown option "1"

sergiol

Posted 2017-07-21T19:00:48.293

Reputation: 3 055

1

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.

Neil

Posted 2017-07-21T19:00:48.293

Reputation: 95 035

1

Tcl, 15

if 1234567890/0

outputs

divide by zero

sergiol

Posted 2017-07-21T19:00:48.293

Reputation: 3 055

1

Ly, 77 bytes

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

Outputs:

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

(note the trailing newline)

LyricLy

Posted 2017-07-21T19:00:48.293

Reputation: 3 313

1

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)

JungHwan Min

Posted 2017-07-21T19:00:48.293

Reputation: 13 290

1

C/*nix, 13 bytes

f(){free(f);}

On minimalist/old systems and shells that don't do fancy things, this prints:

Aborted

Of course, most modern shells print things like:

*** Error in `/tmp/file': munmap_chunk(): invalid pointer: 0x0000000000400536 ***
Aborted

TryItOnline prints a whole host of information.

MD XF

Posted 2017-07-21T19:00:48.293

Reputation: 11 605

Can you give an example of a system that only prints Aborted? (Without the specific checks that glibc uses to detect invalid the free and cleanly call abort(), the program would almost certainly just segfault.) – Anders Kaseorg – 2017-07-22T16:43:08.240

@AndersKaseorg I'm trying to remember on which system this didn't print extra information. I'm not at home so I don't have my ... extensive computer collection, when I get home I'll test it all around. – MD XF – 2017-07-23T22:11:38.127

1

Casio Basic, 10 bytes

{}=>a:a[1]

or, for 12 bytes:

seq(x,x,1,0)

Error for both (6 bytes):

Domain

For the first one, accessing a list element outside the length of the list throws a Domain error. But for some weird reason, you can't access a list index in one go; that is, {}[1] is invalid syntax.

seq generates a list of values for a function with values in a given range; but in this case, specifying a range of 1 to 0 causes a Domain error, since the end is smaller than the start.

numbermaniac

Posted 2017-07-21T19:00:48.293

Reputation: 639

1

VBA, 29 Bytes

Anonymous VBE immediate window function of length 29 which throws Runtime error 6, (len 28) to STDERR

Code

?CByte(Len(Space(127+128+1)))

Error

Run-time error '6':

Overflow

Taylor Scott

Posted 2017-07-21T19:00:48.293

Reputation: 6 709

1

Braingolf, 54 bytes

"ZeroDivisionError: integer division or modulo by z"0/

Try it online!

Throws the 53 byte error ZeroDivisionError: integer division or modulo by zero

Explanation

"ZeroDivisionError: integer division or modulo by z" is a string literal, pushes the error minus 3 bytes.

0 pushes 0, and / attempts to divide the 2nd to last item by the last item, in this case dividing z (122) by 0, which results in a divide by zero error.

Braingolf, 84 bytes

"ValueError: Indices for islice() must be None or an integer: 0 <= x <= sys.maxs"&@@

Try it online!

I personally get this error quite often when screwing around with ASCII art challenges in Braingolf.

Throws a ValueError: Indices for islice() must be None or an integer: 0 <= x <= sys.maxsize. error.

Explanation

"ValueError: Indices for islice() must be None or an integer: 0 <= x <= sys.max" is a string literal. It's just the error minus 4 bytes, because the code must be longer than the error.

&@ then pops and prints the entire stack.

Finally @ attempts to pop and print an item from the now empty stack. Popping from an empty stack produces the above 83 byte error.

Skidsdev

Posted 2017-07-21T19:00:48.293

Reputation: 9 656

1

C++, 26 bytes

int main(){div(1,0);} //??

Result in Windows:

a.exe has stopped working

Robert Andrzejuk

Posted 2017-07-21T19:00:48.293

Reputation: 181

Actually this should require #include<cstdlib>. – ceased to turn counterclockwis – 2017-07-25T19:31:00.673

1

Prolog (SWI), 26 bytes (error: 25 bytes)

a :- a ; a ; a ; a ; a ;a.

Try it online!

This will generate the error: ERROR: Out of local stack (which is, as far as I know, the shortest error message that can be generated by SWI-Prolog).

Explanation

The above program can be simplified to a :- a ; a. (the other ; as are here so that the program is longer than the error message).

The above program says:

a :-      .        % For a to be true…
     a             % Either a…
       ;           % …or…
         a         % …a must be true

This is obviously infinitely recursive, hence why we get an Out of local stack error.

However, the following program:

a :- a.

is also infinitely recursive but will never crash. This is because in that case, tail recursion optimization occurs so that the recursive call does not consume memory.

a :- a ; a. is also tail recursive; however we have introduced a disjunction with ; which prevents the recursive call from not consuming memory, because Prolog has to remember that there was another choice possible to explore instead of each recursive call.


It is possible to generate this same error with other approaches (e.g. using length(_,1000000000) to generate a list too big to fit in memory), but this one is probably the coolest looking one.

Fatalize

Posted 2017-07-21T19:00:48.293

Reputation: 32 976

1

Groovy, 69 bytes

java.lang.Class.metaClass=Integer.metaClass
Integer.metaClass.plus={1}

Error message is:

java.lang.StackOverflowError

I don't know if this will count at 31 bytes, because it will output a lot of line numbers:

a​aaaaaa={aaaaaaa()}​;aaaaaaa()

Output:

java.lang.StackOverflowError
at Script1$_run_closure1.doCall(Script1.groovy:1)
at Script1$_run_closure1.doCall(Script1.groovy)
at Script1$_run_closure1.doCall(Script1.groovy:1)
at Script1$_run_closure1.doCall(Script1.groovy)
...

Fels

Posted 2017-07-21T19:00:48.293

Reputation: 488

1

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

XtremeBaumer

Posted 2017-07-21T19:00:48.293

Reputation: 111

1

MATLAB, 52 44 43 bytes

Another shorter option is to use a function and not provide enough inputs. For example:

qr()%I'm a nice comment to make code longer

Gives this 42 byte error:

Error using qr
Not enough input arguments.

This code (or to be fair any similar code:

[1 1]*[2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ]

Produces the following 51 byte error:

Error using  * 
Inner matrix dimensions must agree.

It's actually surprisingly tricky in MATLAB because when you run any code with syntax errors the error output includes the line of code you ran - which would put a theoretical lower limit on code size of infinity. Fortunately matrix multiplication errors don't do that.

Tom Carpenter

Posted 2017-07-21T19:00:48.293

Reputation: 3 990

I guess this works in MATLAB too? I'm not sure if all work, but I believe some of them should... :)

– Stewie Griffin – 2017-11-09T13:28:17.457

1

C# (.Net, Mono) 25 bytes

class Hi{void There(){_}}

Error:

error CS1002: ; expected

Note: Mono error messages include filename and location before them, so if you named the file P.cs, you'd get this error:

P.cs(1,24): error CS1002: ; expected

Since that part depends on the filename and location of text, I didn't include it. However, if you include it (and make the class name longer or something), you end up with a 36 byte error message and 37 byte program. Let me know if I should change it to that.

TehPers

Posted 2017-07-21T19:00:48.293

Reputation: 899

1

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

Shaun Bebbers

Posted 2017-07-21T19:00:48.293

Reputation: 1 814

1

Aceto, 41 bytes

                                        &

Try it online!

Produces __main__.CodeException: Raised an &rror.

The error message is 40 chars, so...

FantaC

Posted 2017-07-21T19:00:48.293

Reputation: 1 425

1

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).

Kevin Cruijssen

Posted 2017-07-21T19:00:48.293

Reputation: 67 575

1

ed, 3 bytes

?


Returns the following error message (2 bytes).

?

ed is Turing complete, so there shouldn't be issues about whether using it is valid or not. There was a solution in ed before, but it was removed, as there was a concern whether this is a fatal error. I would say, yes, it is, no matter what I did on TIO.run, the execution did not continue after getting an error message. From checking why this happens, it appears that the execution continues only when the code is read from STDIN (REPL mode).

Inspired by https://www.gnu.org/fun/jokes/ed-msg.html

Try it online!

Note that the output contains 0, but it's not a part of an error message, rather it's ed displaying file size by default. It can be removed by using -s flag. If you try changing the input provided to the program, it will change.

Konrad Borowski

Posted 2017-07-21T19:00:48.293

Reputation: 11 185

1

IE9 Chinese version, 9 bytes

'12345'() 

Outputs (assuming GBK encoding)

缺少函数

l4m2

Posted 2017-07-21T19:00:48.293

Reputation: 5 985

0

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.

Koishore Roy

Posted 2017-07-21T19:00:48.293

Reputation: 1 144

You can assume a one-char file name. – Zacharý – 2017-07-21T19:48:02.830

3Then it gets reduced by 8 bytes. I think I can get rid of the last '. HAHAHA' then – Koishore Roy – 2017-07-21T19:49:32.400

why am I getting down votes for this? @Zacharý :( – Koishore Roy – 2017-07-22T16:19:16.267

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⏎. – Anders Kaseorg – 2017-07-22T18:10:22.733

I didn't downvote! – Zacharý – 2017-07-22T20:35:31.753

@AndersKaseorg are we supposed to consider the 'Traceback... last):' portion? I'm asking because the other answer in Python hasn't and hence, neither did I. – Koishore Roy – 2017-07-23T23:12:58.917

1

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.

– Anders Kaseorg – 2017-07-24T01:06:51.560

0

Bash, 20 bytes

"" # waste of space!

Outputs : command not found.

Try it online!

Bash, 21 bytes

b # let's waste space

Outputs: b: command not found.

Try it online!

programmer5000

Posted 2017-07-21T19:00:48.293

Reputation: 7 828

0

Zsh, 24 bytes

"" #lots of wasted space

Outputs zsh: permission denied:.

Try it online!

programmer5000

Posted 2017-07-21T19:00:48.293

Reputation: 7 828

0

Haystack, 21 bytes

Wasted space is good!

Errors with Where's the needle?. Dosen't work on TIO.

programmer5000

Posted 2017-07-21T19:00:48.293

Reputation: 7 828

0

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.

Uriel

Posted 2017-07-21T19:00:48.293

Reputation: 11 708

0

Applesoft BASIC, 14 bytes

SYNTAX ERROR??

Output:

?SYNTAX ERROR

MD XF

Posted 2017-07-21T19:00:48.293

Reputation: 11 605

0

ExtraC, 21 bytes

Invalid character: : 

Try it online!

If you remove the space after the second :it is a error quine

Christopher

Posted 2017-07-21T19:00:48.293

Reputation: 3 428

0

Javascript 79 bytes

clear(this);
a=0;
typein:2: TyperError: attempt to run compile-and-go script on a

Christopher

Posted 2017-07-21T19:00:48.293

Reputation: 3 428

https://codegolf.stackexchange.com/a/61126/63187 ripped from – Christopher – 2017-07-23T02:05:30.647

0

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.

Keyu Gan

Posted 2017-07-21T19:00:48.293

Reputation: 2 028

0

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.

manassehkatz-Moving 2 Codidact

Posted 2017-07-21T19:00:48.293

Reputation: 129

-1: That´s not a fatal error. – Titus – 2017-10-24T16:41:25.967

Actually, you're right. Warnings aren't fatal. In a quick search I haven't found the right setting yet... – manassehkatz-Moving 2 Codidact – 2017-10-24T16:51:06.460

I´d give +1 for the exact counting, but my vote is locked. – Titus – 2017-10-24T20:40:41.687

0

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.

jacwah

Posted 2017-07-21T19:00:48.293

Reputation: 101

0

><>, 26 Bytes

Code: "we'refinehereuntilthis!"z

Error: Something smells fishy...

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

Stegosaurus

Posted 2017-07-21T19:00:48.293

Reputation: 101

@HyperNeutrino already posted this. https://codegolf.stackexchange.com/questions/133840/shortest-error-message?#133844

– meneken17 – 2017-07-30T00:19:46.847

0

JavaScript, 13 bytes

prompt(alert(

Error produced (12 bytes):

Expected ')'

user75200

Posted 2017-07-21T19:00:48.293

Reputation: 141

Which browser? Firefox gives: SyntaxError: expected expression, got end of script – RuteNL – 2017-11-09T13:51:03.047

0

SmileBASIC console, 12 11 bytes

?@L*EXP(22)

Error message (8 or 9 bytes):

Overflow

Must be run from the console, otherwise it outputs a line number. Normally errors are formatted like {error} in {slot}:{line}({func}:{arg}), but this error isn't caused by a function and doesn't have a line number so only the error name is shown.

EXP(x) returns e^x, and e^22 is 3584912846.131588. This is outside the 32 bit signed integer range of -2147483648 to 2147483647. Multiplying a string (@L) by this value converts it to an integer, causing an overflow error.

12Me21

Posted 2017-07-21T19:00:48.293

Reputation: 6 110

I'd consider calling the language SmileBASIC (DIRECT), since REPLs and similar environments are considered separate languages. – snail_ – 2018-06-26T20:51:32.557

Also, you can get the same error with I%=999E99 for 9 bytes. – snail_ – 2018-06-26T20:52:41.910

The console isn't a REPL though. – 12Me21 – 2018-06-26T21:29:03.153

"REPLs and *similar environments*" it's close enough that I'd count it, since it is "type in a statement and it runs" – snail_ – 2018-06-27T04:06:06.423

0

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:

sundar - Reinstate Monica

Posted 2017-07-21T19:00:48.293

Reputation: 5 296

0

Attache, 40 bytes

A Reference Error: Undefined variable!!!

Try it online!

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

Conor O'Brien

Posted 2017-07-21T19:00:48.293

Reputation: 36 228

0

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.

Ciaran_McCarthy

Posted 2017-07-21T19:00:48.293

Reputation: 689

1The 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.

– lukass – 2018-06-27T13:14:16.850

1I'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... – Ciaran_McCarthy – 2018-06-27T13:17:44.917

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 :) – lukass – 2018-06-27T15:37:39.990

0

Go, 36 bytes

package verylongnamednonmainpackage;

Produces:

go run: cannot run non-main package

lukass

Posted 2017-07-21T19:00:48.293

Reputation: 71

0

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!

famous1622

Posted 2017-07-21T19:00:48.293

Reputation: 451

0

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)

SuperJedi224

Posted 2017-07-21T19:00:48.293

Reputation: 11 342

0

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)

canttalkjustcode

Posted 2017-07-21T19:00:48.293

Reputation: 131

0

Python, 30 bytes

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

Error: ValueError: math domain error (29 bytes)

Sagittarius

Posted 2017-07-21T19:00:48.293

Reputation: 169

0

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 :=.

user15259

Posted 2017-07-21T19:00:48.293

Reputation: