text:
Shortest Error Message
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 '['

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

@Dennis I guess that's one way of solving the "OP doesn't edit clarifications into question" problem.

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.

@smartpeople is this: "__main__.CodeException: Raised an &rror."  my error or is this:"Raised an &rror."

TrumpScript running in China?

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.

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):
?

Actually, this is impossible to beat. :P

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.

Can ed do addition and primality testing? Or is that not required for this type of challenge?

@StepHen Yes, it can do addition and primality testing in unary via the usual regex-with-backreferences trick.

well, you got my upvote :D

This answer was exactly my first thought on reading the question.  Ed is justly famed for its succinct error messages.

Very clever, but '?' isn't fatal.

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.

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

This outputs 0\n?\n to STDERR, which is longer than the source code. This can be fixed at no cost, however, by using -s.

@Makonede The 0\n only appears when providing a 0-byte input file as an argument to ed. The TIO wrapper does this, but one doesn’t need to do so in general. If one does, the 0\n is not part of an error message: it appears before any code is read, and indicates the size of the input file.

C (modern Linux), 19 bytes
Would've done my famous segfault but totallyhuman stole it.
main(){longjmp(0);}

Output (18 bytes):
Segmentation fault

You currently have a higher score than me so... Win-win?

Let us continue this discussion in chat.

Are there no other locale with a shorter version (So that you could then use main(){main();})?

@12431234123412341234123 Not that I know of. Also, main(){main();} is not guaranteed to seg-fault.

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

How about main(){free(1);}? On my device, it aborts.

Python 2, 35 bytes
import sys;sys.tracebacklimit=000;a

Gives error:
NameError: name 'a' is not defined

modifying the traceback limit... nice one

This is clever!

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.

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

You can assume a one-char file name!

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

Heh, nice. - - -

But the error message has to be smaller than the program itself...

@LeakyNun Fixed.

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

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

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

I like it, and it's definately the most fishy of all solutions :-)

@Xan-KunClark-Davis sigh you had to... :P

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.

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

@EngineerToast thanks, didn't think of that one.

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.

Please explain...

@MegaMan Updated with explanation.

Upvote for actually enlightening explanation.

JavaScript (Firefox), 21 bytes
(a=null)=>a.charAt(1)

Error (20 bytes): TypeError: a is null

D'oh! I knew there was a shorter one...

I had the same idea, came up with a=null;a.x01234567890
Same amount of bytes

TrumpScript, 30 bytes
We love NATO!
America is great

Error message:
Trump doesn't want to hear it

P.S. Error codes are in constants.py

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.

Welcome to PPCG!

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

Vyxal, 309 bytes
In this answer, I coded it so that the program errors when executed․
Also, according to code-golf statistics, only a small percentage of people who view my answers actually upvote․
So if you enjoy this answer, please consider upvoting - it's free, and you can change your mind at any time․
Enjoy the answer․

I request that you imagine Epic Dawn by Bobby Cole is playing while reading this answer.
The Error
Traceback (most recent call last):
  File "C:\Users\61419\Desktop\Vyxal\Vyxal.py", line 867, in <module>
    exec(line)
  File "<string>", line 4, in <module>
  File "C:\Users\61419\Desktop\Vyxal\Vyxal.py", line 592, in VY_int
    return int(item, base)
ValueError: invalid literal for int() with base 10: ''

Explained
This fails immediately on the first instruction it sees: I. It tries to convert the empty input to base 10 (which is impossible)

PPCG: YouTube edition.

-308 bytes (2.4.1 online only)

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

But the error message has to be smaller than the program itself...

Byte counts were screwed up, my bad.

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

@totallyhuman DV was mine, forgot to reverse it after we cleared up the issue.

@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 Is WIFEXITED(wstatus) equivalent to DIVORCE(alimony) by any chance?

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

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

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

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 Yeah, I found that amusing as well.

You can use a one char file name!

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

That's fine (the ! wasn't needed), since this definitely won't be winning anything.

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 Nice job polling the code to find a shorter error message. Thanks!

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!

a #abcdefghijklmnopqrstuvwxy's error Error: object 'a' not found is one byte shorter.

@JarkoDubbeldam thank you.

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

Welcome to PPCG!

@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: I actually wrote a bruteforce program and tested every possible 1, 2 and 3-byte Ruby program :D Thanks for the link.

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

I guess choosing an interpreter is as much a part of the challenge as choosing a language.

@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 :)

Who beats brainfuck? Nobody? Alright.

The unbeatable solution would a two byte solution which causes an error of 1 character.

@Zacharý Certainly lol

weird interpreter; wraps calls value but not cells layout

@Uriel It is quite weird. Of course, I'm abusing that just because it exists :)

The reasonable thing for brainfuck is to support an infinite number of cells of infinite value on both sides.

Common Lisp, 20 bytes
(/ 1 0))))))))))))))

Try it online!
Error Message
/: division by zero

o_o unbalanced parentheses in Lisp ... you learn something new every day.

If 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

TryAPL, 11 bytes
Code (11):
'abcdefghij

Error (10):
open quote

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)

ZX Spectrum Basic, 9 bytes
RUN USR 8

produces:

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.

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.

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.

It seems nor valid to me. IIRC die is for the program to exit.

How is that any different than python raise?

Well, the OP might have been referring to either generating the error or the error message. I commented on which one he meant.

Perl 5, 5 bytes
die$/

Outputs a newline, for one byte.
Try it online!

._. Now ... if only perl errors on the empty file!

Wait, is this a violation of the "may not be generated by the program itself"? I didn't understand what that rule was saying.

@Zacharý ... giving an error message with total length negative one?

This might be invalid ... or not, depends on whether the OP meant the error or the error message

^ clarification: whether a program errors directly or creates an error message directly

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.

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.

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

05AB1E, 410 411 bytes
One plus one is two, two plus two is four.
And now, some random character spam just because I can.
3...
2...
1...
GO!

ooi1u4`o1i2)I#1n[09i43u`1@#~!@#{10239`]ι@(~!)2ioausioe7u12o3iu71p3123`71i2`8127l5ruy;3948'p3298rv9pe8huep'r8i19o`8u'3pie8uiouI!^23uT7T17I3YJH~:L'I`YU2O123;121@

That should be about it, it errored. Guess that's what happens when you spam. Bye for now!

upvote if you liked my creativity

:)

Try it online!
One plus one i...]ι...  # trimmed program
One plus one            # push empty string ("") twice
             i          # if top of stack is truthy...
              ...       # execute (trimmed) code (this is unreachable)
                 ]      # exit all opened statements
                  ι     # not exactly sure what this function does, but part of it forcefully converts top of stack to an integer (without error handling), therefore erroring
                   ...  # unreachable code as program has quit from the fatal error

Error, 410 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

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!

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)

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

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.

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.

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.

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

BASIC (BBC micro)  9 bytes
>REN 9,-5
Silly.

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.

I think you should separate your answers.

@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 26 25, but it's often for minor changes.

Actually, I'm not sure why I said that, so nevermind.

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.

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.

LibreOffice Calc, 7 bytes
=aaaaaa

Result:
#NAME?

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.

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.

IE9 Chinese version, 9 bytes
'12345'()

Outputs (assuming GBK encoding)
缺少函数

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

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.

Python 3, 29 Bytes
from __future__ import braces

Error
SyntaxError: not a chance

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.

Same byte count different approach

J, 10 bytes
0000000^.0

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

Japt, 32 bytes
????????????????????????????????

Error message (31 bytes):
SyntaxError: Unexpected token ?
Try it online!

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

Another reminder that I probably shouldn't still be using alert for errors :P

@ETHproductions: if it wasn't for the intrusive alert, I probably wouldn't have remembered that error existed!

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

Batch 90 18 bytes
@set/ab=1+*2*3*4*5

Missing Operand\
Golfed by SteveFest

This shold work: @set/ab=1+2+345) - Missing Operand

I was wrong: @set/ab=1+*2*3*4*5 - Missing Operator It's just as few bytes. I'm sorry :(

@SteveFest that is fine XD

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.

The ! in the first line messes up the debug a bit

@JoKing Fixed, I believe.

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

PHP, 56 bytes
<?php aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

produces
PHP Parse error:  syntax error, unexpected end of file

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

point. Why do I remember a leading newline now? I´m confusing myself.

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

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.

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 that sounds like a sufficiently different approach that you could make it an answer.

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.

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.

In MATLAB this would give a 33 byte error message (Index exceeds matrix dimensions.\n ). Still, beats mine by 9 bytes.

@, 29 bytes
Error: Unknown instruction E!

This tries to call the function E, which does not exist.
Output message:
Error: Unknown instruction E

I don't think the error is 'smaller than the program itself'

I switched the language. (Introducing the @ language)

Rust, 61 57 bytes
fn main()->Result<(),usize>{[].binary_search(&0)?;Ok(())}

Try it online!
Returns from the main function with Error: 0.
-3 bytes thanks to Anders Kaesorg

I believe the goal is to make the error message shorter than the code.

@EasyasPi Fixed

.ok_or(0) seems like it breaks the rule that “the error message may not be generated by the program itself”. (But if not, 47 bytes.)

@AndersKaseorg I think you're right, I found another 61-byte answer. Nice spot, though.

Your answer works on a slice too: 57 bytes

Red, 29 Bytes
a/1/1/1/1/1/1/1/1/1/1/1/1/1/1

Script Error: a has no value

Welcome to the site! I fixed the formatting, you can revert it if you preferred the original.

Shakespeare Programming Language, 100 bytes
,.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck]Ajax:You cat!You is the quotient betweenyou zero.

Try it online!
which produces
Runtime error at line 1: Unable to divide 1 by zero!

The error is 53 bytes including the trailing newline.
I really don't see how this can be improved (unless I missed something obvious). It loads 1 into Puck and attempts to divide him by 0.

CPython 3.9, 71 bytes
__peg_parser__
########################################################

Not the shortest, but I found this "feature" worth sharing nonetheless: when Python 3.9 switched to a PEG parser, there was a special easter egg keyword __peg_parser__ added which immediately causes a syntax error. The error outputted is:
  File "a", line 1
    __peg_parser__
    ^
SyntaxError: You found it!

This was removed in Python 3.10.

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

You can use a one char file name

Yeah, Thanks.... But to make it more TIO-interactive... if you know what I mean..

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

You can use a one char file name (TIO ... why)

@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

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

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)

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.

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

@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 Are you going to measure JungHwan's answer, too, (?) or this is just about my answer?

@Jenny_mathy Mostly about your answer, I didn't know that JungHuan answered.

yes, it is quite funny! posting all these things on the main chat and doing exactly the same!

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

Edited version is very nice. 5/7 perfect score.

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!

Lua, 45 bytes
0/###########################################

Try it online!
Error message, 44 bytes
lua: .code.tio:1: unexpected symbol near '0'

You can use a one char file name!

I think its better that officialaimm didn't. Beat my example by 1. :P

How is it better that he didn't?

It's not a better result, I just found it more funny that he beat the example by exactly 1 byte.

That would be because I had forgotten the example was in Lua and I don't really know lua... :D

Haystack, 21 bytes
Wasted space is good!

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

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.

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

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

@MDXF found any?

C++, 26 bytes
int main(){div(1,0);} //??

Result in Windows:
a.exe has stopped working

Actually this should require #include<cstdlib>.

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.

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.

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:
aaaaaaa={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)
...

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.

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

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.

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.

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

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.

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.

I'd consider calling the language SmileBASIC (DIRECT), since REPLs and similar environments are considered separate languages.

Also, you can get the same error with I%=999E99 for 9 bytes.

The console isn't a REPL though.

"REPLs and similar environments" it's close enough that I'd count it, since it is "type in a statement and it runs"

Aceto, 41 bytes
                                        &

Try it online!
Produces __main__.CodeException: Raised an &rror.
The error message is 40 chars, so...

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.

naz, 38 bytes
1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a4x

Explanation
1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a   # Add 1 to the register 18 times
                                    4x # Set the current opcode to 4

The only opcodes accepted by the naz interpreter under any circumstances are 0 (normal operation), 1 (function write), 2 (variable write), and 3 (conditional). Thus, if run from a file with a one-letter filename (e.g. f.naz), this program will produce the following 37-byte error:
error: invalid opcode
  at f.naz:1:38

COBOL(GNU), 47 bytes
PROCEDURE DIVISION. HELLO. HELLO. HELLO. HELLO.

Outputs:
main.cobc: 1: error: PROGRAM-ID header missing
Assuming filename = main.cobc

Setanta, 12 bytes
1/0 >--- uwu

This produces the 11-byte error message Roinnt ar 0.
Try it here

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.

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

The code must be at least one byte longer than the error message.

This is C++ code!

@Zacharý Oups! Thanks for the correction!

And ... you can use a one char file name.

Would this work? printf("%s", variable)=>printf("%s",variable)?

@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 :)

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.

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.

You can assume a one-char file name.

Then it gets reduced by 8 bytes.
I think I can get rid of the last '. HAHAHA' then

why am I getting down votes for this? @Zacharý :(

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

I didn't downvote!

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

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.

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

Try it online!
Produces the error
BrainHack: Prelude.chr: bad argument: (-1)

Zsh, 24 bytes
"" #lots of wasted space

Outputs zsh: permission denied:.
Try it online!

Tcl/Tk, 19
pack [text .text 1]

outputs
18
unknown option "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.

Tcl, 15
if 1234567890/0

outputs
divide by zero

Ly, 77 bytes
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[

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

(note the trailing newline)

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)

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.

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.

Applesoft BASIC, 14 bytes
SYNTAX ERROR??

Output:
?SYNTAX ERROR

ExtraC, 21 bytes
Invalid character: :

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

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

https://codegolf.stackexchange.com/a/61126/63187 ripped from

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.

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.

-1: That´s not a fatal error.

Actually, you're right. Warnings aren't fatal. In a quick search I haven't found the right setting yet...

Try https://akrabat.com/convert-php-warnings-and-notices-into-fatal-errors/

I´d give +1 for the exact counting, but my vote is locked.

><>, 26 Bytes
Code: "we'refinehereuntilthis!"z
Error: Something smells fishy...
All ><> errors are Something smells fishy...

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

JavaScript, 13 bytes
prompt(alert(

Error produced (12 bytes):
Expected ')'

Which browser? Firefox gives: SyntaxError: expected expression, got end of script

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:

Attache, 40 bytes
A Reference Error: Undefined variable!!!

Try it online!
Message (39 bytes): Reference Error: Undefined variable "A"

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.

The question requires an error message shorter than the program:

Write the shortest program that, when compiled or executed, produces a fatal error message smaller than the program itself.

I've no idea why, but I read the question as "longer". Damn. Now that I think about it, that makes more sense as a challenge too...

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

Go, 36 bytes
package verylongnamednonmainpackage;

Produces:
go run: cannot run non-main package

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!

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)

C# .NET, 59 bytes
public class P{static void Main(){int je=0;int iee=je/je;}}

Try OnlineProduces 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)

Python, 30 bytes
import math as ma; ma.sqrt(-1)

Error: ValueError: math domain error (29 bytes)

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

C, Bionic libc (Android, Termux), 16 characters
main(){free(1);}

Output, 8 characters (including newline)
Aborted

Python, 35 bytes
Pretty simple.
print(a)###########################

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

Whitespace (wspace 0.3), 19 bytes
SSSSL
SLS
TSTS
TLST
LLL

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

Renaming wspace to w gives a shorter error message.
$ ln -s ~/bin/wspace w
$ ./w codegolf/shortest_error.ws
w: divide by zero
$ ./w shortest_error.ws 2>| wc -c
      18
$ wc -c < shortest_error.ws
      19

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

Raku (Perl 6) (rakudo), 38 bytes
die#iaj zav; xbsio la, n v km l s zioa

When run using raku -e, this produces the 37-byte output
Died
  in block <unit> at -e line 1

Attempt This Online!

Swift, 46 bytes
let message = "what do you want it to do?"
let

Try the fiddle!
Error, 45 bytes (when compiled from standard input)
<stdin>:2:4: error: expected pattern
let
   ^

Vyxal 3, 38 bytes
222222222222222222222222222222222222[x

Try it Online!
RuntimeException: Too many recursions

YASEPL, 38 bytes
=p/0+000000000000000000000000000000000

error message:
ERROR 8 divide by 0:(

located at /0

Go, 67 bytes
package main
func main(){var f string = "aaaaaaaaaaaaaaaaaaaaaaaa"}

Attempt This Online!
Gives the following error (66 bytes):
# command-line-arguments
../code.go:2:17: f declared and not used


text:
Compute the antipode of a point on curve
A curve is a set of points on a square grid such that each point has exactly two neighbors in the four-neighbor neighborhood and the points form a single connected component. That is, the graph induced by the points on a grid graph is isomorphic to a single cycle. "Induced" means that two points cannot touch in the input without being neighbors in the cycle.
An antipode of a vertex V in a graph is a vertex furthest away from V. The antipode is always unique on an even-length cycle (and every cycle on a grid graph is even-length). The distance shall be measured as induced by the cycle itself without respect for the underlying square grid.
Your input shall be an image of a curve. The curve will be marked out with a sequence of number sign characters (#) on a background out of space characters (). One of the points on the curve will be marked with the P character ("pode"). Your output shall be the same as the input except one curve point shall be replaced with A ("antipode").
You may assume the characters will be padded to a rectangular shape. You may assume the first and last row and column of input will be composed entirely of spaces (input is padded with background). Alternatively you may assume that the first and last row and column will each contain a curve point (input has minimum padding).
You may input and output this grid as a single newline-separated string, as an array of rows, or as a 2D array of individual characters. This choice shall be the same for the input and output. If your language allows this, you may output by modifying the input in place instead of returning the modified string or array.
Possible inputs:
P#    P##   #P#   #####      #####P# #######   #####P#########   #####P#########
##    # #   # #   #   #      #     # #     #   #             #   #             #
      ###   ###   ## ##      # ### # # ### #   # ### ### ### #   #             #
###                # # ###   # # # # # # # #   # # # # # # # #   #             #
# P#    ### ###    # ### #   # # ### ### # #   # # ### ### # #   #             #
## #    # ### #    #     #   # #         # #   # #         # #   #             #
 # #    P     #    ##### P   # ########### #   # ##### ##### #   #             #
 ###    #######        ###   #             #   #     # #     #   #             #
                             ###############   ####### #######   ###############

Corresponding outputs:
P#    P##   #P#   #A###      #####P# #A#####   #####P#########   #####P#########
#A    # #   # #   #   #      #     # #     #   #             #   #             #
      ##A   #A#   ## ##      # ### # # ### #   # ### ### ### #   #             #
###                # # ###   # # # # # # # #   # # # # A # # #   #             #
# P#    ### ##A    # ### #   # # ### ### # #   # # ### ### # #   #             #
## #    # ### #    #     #   # #         # #   # #         # #   #             #
 A #    P     #    ##### P   # ########### #   # ##### ##### #   #             #
 ###    #######        ###   #             #   #     # #     #   #             #
                             ###############   ####### #######   #########A#####

Vertex distances from the podes (modulo 10) (do not output these):
P1    P12   1P1   5A543      54321P1 9A98765   54321P123456789   54321P123456789
1A    1 3   2 2   4   2      6     2 8     4   6             0   6             0
      23A   3A3   32 01      7 109 3 7 109 3   7 901 789 543 1   7             1
321                1 9 543   8 2 8 4 6 2 8 2   8 8 2 6 A 6 2 2   8             2
4 P1    234 89A    0 876 2   9 3 765 543 7 1   9 7 345 987 1 3   9             3
56 2    1 567 9    9     1   0 4         6 0   0 6         0 4   0             4
 A 3    P     8    87654 P   1 56789012345 9   1 54321 56789 5   1             5
 654    1234567        321   2             8   2     0 4     6   2             6
                             345678901234567   3456789 3210987   345678901A10987

Python 2, 333 221 215 bytes
-17 bytes thanks to @JanDvorak
g=input()
y=map(max,g).index('P')
x=g[y].index('P')
m=[k[:]for k in g]
v=x;w=y
while'#'in sum(m,[]):x,y,(v,w)=v,w,[(x+a,y+b)for a,b in((1,0),(-1,0),(0,1),(0,-1))if'#'==m[y+b][x+a]][0];m[w][v]='_'
g[w][v]='A'
print g

Try it online!

Python 3, 402 288 282 bytes, String IO
g=[[*k]for k in open(0).read().split('\n')]
y=[max(k)for k in g].index('P')
x=g[y].index('P')
m=[k[:]for k in g]
v=x;w=y
while'#'in sum(m,[]):x,y,(v,w)=v,w,[(x+a,y+b)for a,b in((1,0),(-1,0),(0,1),(0,-1))if'#'==m[y+b][x+a]][0];m[w][v]='_'
g[w][v]='A'
print('\n'.join(map(''.join,g)))

Try it online!

Animation of the code running:

JavaScript (ES6), 193 181 bytes
f=s=>s==(`P#1P#21#12#221A`[r=`replace`](/.../g,([n,f,t])=>s=s[r](eval(`/([${n+=f}])([^]{${s.search`\n`}})?(?!\\1)[${n}]/`),m=>m[r](eval(`/^${f}|${f}$/`),t))),s)?s[r](/\d/g,`#`):f(s)

Version that provides a looping animation:

f=s=>s==(`#A#1#12#221AP#1P#2`[r=`replace`](/.../g,([n,f,t])=>s=s[r](eval(`/([${n+=f}])([^]{${s.search`\n`}})?(?!\\1)[${n}]/`),m=>m[r](eval(`/^${f}|${f}$/`),t))),s)?s[r](/\d/g,`#`):s
;setInterval(_=>i.value=f(i.value),1e3)
<textarea rows=10 cols=20 id=i style="font-family:monospace"></textarea>

MATL, 43 42 bytes
32-I#fbbJ*+!w3>y"&)yy-|&X<]vJQ2/)G65b&Zj&(

The code accepts an arbitrary amount of space padding in the first and last rows and columns. Input is a rectangular array of chars, using ; as row separator. For example, the input
#####
#   #
## ##
 # # ###
 # ### #
 #     #
 ##### P
     ###

is represented as
['#####   ';
 '#   #   ';
 '## ##   ';
 ' # # ###';
 ' # ### #';
 ' #     #';
 ' ##### P';
 '     ###']

or, in one line (so it can be entered through STDIN),
['#####   '; '#   #   '; '## ##   '; ' # # ###'; ' # ### #'; ' #     #'; ' ##### P'; '     ###']

Try it online! Or verify the last four cases: 1, 2, 3, 4 (these have been chosen because they have the most complicated curves; the last one has some space padding).
Explanation
TL;WR: Complex numbers, lots of indexing, no convolution.
32-     % Implicitly input char matrix. Subtract 32. Space becomes zero
I#f     % 3-output find: pushes nonzero values, their row indices,
        % and their column indices, as column vectors
bb      % Bubble up twice, so row and column indices are on top
J*+     % Times 1j, add. This transforms row and column indices into
        % complex numbers, where real is row and imaginary is column
!       % Transpose into a row vector
w       % Swap, so vector of nonzero values is on top
3>      % Logical index of elements exceeding 3. ASCII codes of space,
        % '#' and 'P0 are 32, 35 and 80 respectively. Since 32 was
        % subtracted these became 0, 3 and 48. So the only entry with
        % value exceeding 3 is that corresponding to the original 'P'.
y"      % Do this as many times as the number of complex positions
        %   The stack now contains the vector of complex positions and an
        %   index into that vector. The index points to the complex position
        %   to be processed next.
  &)    %   Two-output reference indexing: pushes the indexed entry and
        %   a vector with the remaining entries. This pulls off the
        %   current complex position, which is initially that of 'P'
  yy    %   Duplicate top two elements, i.e. current position and vector
        %   of remaining positions
  -|    %   Absolute differences
  &X<   %   Index of minimum. Gives the index of the complex position
        %   that is closest to the current one. In case of tie (which
        %   only happens in the first iteration) it picks the first. The
        %   result is the index of the complex position to be processed in
        %   the next iteration. This index will be empty if this is the last
        %   iteration.
]       % End
        % The stack now contains the complex positions as individual
        % values, starting from 'P' and sorted as per the curve; plus two
        % empty arrays. These empty arrays have been produced by the last
        % iteration as the index for the "next" iteration and the array of
        % "remaining" complex positions
v       % Concatenate into a column vector. The empty arrays have no effect.
        % The resulting vector contains the sorted complex positions
JQ      % Push 1j and add 1
2/      % Divide by 2. This gives (1+1j)/2. When used as an index this is
        % interpreted as (1+end)/2. Since the length of the curve is even
        % this gives a non-integer number, which will be implicitly
        % rounded up (because of .5 fracctional part). As an example, for
        % length 32 this gives 16.5, which rounded becomes 17. Position 17
        % along the curve is the antipode of position 1
)       % Reference indexing. Gives the complex position of the antipode
G       % Push input char matrix again
65      % Push 65 (ASCII for 'A')
b       % Bubble up, so complex position is on top
&Zj     % Separate into real and imagimary parts, corresponding to row and
        % column indices
&(      % 4-input assignment indexing. This writes 'A' at the specified row
        % and column of the char matrix. Implicitly display

Python 3, 421 bytes
l,e=len,enumerate
r=open(0).read()
n=lambda x:[(x[0]-1,x[1]),(x[0]+1,x[1]),(x[0],x[1]-1),(x[0],x[1]+1)]
p=a={(i,j):y for i,x in e(r.split('\n'))for j,y in e(x)}
t=l(r.split('\n'));s=l(r.split('\n')[0])
for i in a:p=[p,i][a[i]=='P']
w=[p]
while l(w)!=r.count('#')+1:
 for x in a:
  if x in n(w[-1])and a[x]!=' 'and x not in w:w+=[x]
a[w[(l(w)+1)//2]]='A';print('\n'.join(''.join(a[j,i]for i in range(s))for j in range(t)))

Try it online!

Mathematica, 234 223 bytes
(p=Position;v=p[#,"#"|"P"];n=Length@v;q=v[[#]]&;h=FindCycle[Graph[v,Join@@Table[If[Norm[q@i-q@j]==1,q@i<->q@j,Nothing],{i,n},{j,i-1}]]][[1,#,1]]&;ReplacePart[#,h@Mod[p[Table[h@x,{x,n}],p[#,"P"][[1]]][[1,1]]+n/2,n,1]->"A"])&

This code makes v be the vertex list for the graph: the indices of the "#" and "P"s. Then n is the length (necessarily even) and q extracts the input-th vertex (so ignoring the shape of the loop).
Then h is a function that builds the graph with vertices in v and undirected edges between vertices when the length of the difference of their index pairs is exactly 1 (so their difference is something like {-1,0} or {0,1}) and then finds a list of all cycles and provides the first (only) cycle (as a list of edges) and then takes the input-th edge and takes the first vertex making up that edge.
Using h, we can find the index of the "P" in the cycle, and go halfway around (using Mod to wrap around if we go past the bounds of the cycle list) to find the antipode, and then we can replace the corresponding entry of the original input m with "A"
You can try it online with by pasting the following at the Wolfram Cloud Sandbox and clicking "evaluate cell" or hitting Shift+Enter or Numpad Enter:
(p=Position;v=p[#,"#"|"P"];n=Length@v;q=v[[#]]&;h=FindCycle[Graph[v,Join@@Table[If[Norm[q@i-q@j]==1,q@i<->q@j,Nothing],{i,n},{j,i-1}]]][[1,#,1]]&;ReplacePart[#,h@Mod[p[Table[h@x,{x,n}],p[#,"P"][[1]]][[1,1]]+n/2,n,1]->"A"])&@{{"#","#","#","#","#"," "," "," "},{"#"," "," "," ","#"," "," "," "},{"#","#"," ","#","#"," "," "," "},{" ","#"," ","#"," ","#","#","#"},{" ","#"," ","#","#","#"," ","#"},{" ","#"," "," "," "," "," ","#"},{" ","#","#","#","#","#"," ","P"},{" "," "," "," "," ","#","#","#"}}//MatrixForm

Alternative idea, 258 bytes
Slightly inspired by ovs's Python solutions, I tried to write code that would not use any graph theory features of Mathematica and just blindly calculate the distances. I couldn't get it as short, but suspect someone could improve it:
f[m_]:=(x="#";t=ReplacePart;p=Position;l=t[m,p[m,"P"][[1]]->0];v=p[l,x|0];n=Length[v];q=v[[#]]&;r=l[[q[#][[1]],q[#][[2]]]]&;y=t[l,q@#->(r@#2+1)]&;Do[If[Norm[q@i-q@j]==1&&Xor[r@i==x,r@j==x],If[r@i==x,l=y[i,j],l=y[j,i]]],n,{i,n},{j,n}];t[m,p[l,n/2][[1]]->"A"])`

This code is very inefficient. Basically, it replaces "P" with 0 and then looks for a "#" next to something that's not a "#" by looping through the entire thing twice and replaces them with numbers representing the distance from "P", and to make sure it finishes, it does that process n times. This actually doesn't even calculate distances correctly since one branch could go past the antipode, but only one location will be numbered with n/2 no matter what.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Golf me a memory array
This challenge is pretty simple: Your task is to draw a schematic of a (simplified) memory array. You will be given two (positive) integers n,m and the task is to draw the n:2^n decoder connected to the memory array with d data lines.
The addressing will be in the order of gray codes, to check if the sequence is correct, see A014550. For simplicity there are no input ports, write ports etc. On the top of the decoder you need to specify its type (e.g. 2:4) and you will label the data lines with d:[d-1],...,d:1,d:0. If the cray code wouldn't fit the decoder width, you'll need to expand the width, see the last two examples.
Rules

Leading whitespaces are not allowed
Trailing whitespaces are allowed
At the end of the output there may be one or several newlines
You can assume the following constraints on the input 0 < n and 0 < d <= 1e4
The output is either printed to the console or you write a function that returns a newline-separated string
For invalid input the behaviour of your program/function is left undefined

Test cases
n = 1, d = 1

.-----.
| 1:2 |
|     |
|    0|---+
|     |   |
|     |  .+.
|     |  | +-+
|     |  `-' |
|    1|---+  |
|     |   |  |
|     |  .+. |
|     |  | +-+
|     |  `-' |
`-----'      |
            d:0

n = 1, d = 10

.-----.
| 1:2 |
|     |
|    0|---+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|     |   |     |     |     |     |     |     |     |     |     |
|     |  .+.   .+.   .+.   .+.   .+.   .+.   .+.   .+.   .+.   .+.
|     |  | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+
|     |  `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' |
|    1|---+--(--+--(--+--(--+--(--+--(--+--(--+--(--+--(--+--(--+  |
|     |   |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
|     |  .+. | .+. | .+. | .+. | .+. | .+. | .+. | .+. | .+. | .+. |
|     |  | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+ | +-+
|     |  `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' | `-' |
`-----'      |     |     |     |     |     |     |     |     |     |
            d:9   d:8   d:7   d:6   d:5   d:4   d:3   d:2   d:1   d:0

n = 2, d = 3

.-----.
| 2:4 |
|     |
|   00|---+-----+-----+
|     |   |     |     |
|     |  .+.   .+.   .+.
|     |  | +-+ | +-+ | +-+
|     |  `-' | `-' | `-' |
|   01|---+--(--+--(--+  |
|     |   |  |  |  |  |  |
|     |  .+. | .+. | .+. |
|     |  | +-+ | +-+ | +-+
|     |  `-' | `-' | `-' |
|   11|---+--(--+--(--+  |
|     |   |  |  |  |  |  |
|     |  .+. | .+. | .+. |
|     |  | +-+ | +-+ | +-+
|     |  `-' | `-' | `-' |
|   10|---+--(--+--(--+  |
|     |   |  |  |  |  |  |
|     |  .+. | .+. | .+. |
|     |  | +-+ | +-+ | +-+
|     |  `-' | `-' | `-' |
`-----'      |     |     |
            d:2   d:1   d:0

n = 4, d = 5

.------.
| 4:16 |
|      |
|  0000|---+-----+-----+-----+-----+
|      |   |     |     |     |     |
|      |  .+.   .+.   .+.   .+.   .+.
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  0001|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  0011|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  0010|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  0110|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  0111|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  0101|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  0100|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  1100|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  1101|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  1111|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  1110|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  1010|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  1011|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  1001|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
|  1000|---+--(--+--(--+--(--+--(--+  |
|      |   |  |  |  |  |  |  |  |  |  |
|      |  .+. | .+. | .+. | .+. | .+. |
|      |  | +-+ | +-+ | +-+ | +-+ | +-+
|      |  `-' | `-' | `-' | `-' | `-' |
`------'      |     |     |     |     |
             d:4   d:3   d:2   d:1   d:0

n = 1, d = 1024    (output truncated!)

.-----.
| 1:2 |
|     |
|    1|---+-----+----...
|     |   |     |    ...
|     |  .+.   .+.   ...
|     |  | +-+ | +-+ ...
|     |  `-' | `-' | ...
|    0|---+--(--+--(-...
|     |   |  |  |  | ...
|     |  .+. | .+. | ...
|     |  | +-+ | +-+ ...
|     |  `-' | `-' | ...
`-----'      |     | ...
            d:1023d:1022d:1021...

n = 10, d = 1    (output truncated!)

.-----------.
| 10:1024   |
|           |
| 0000000000|---+
|           |   |
|           |  .+.
|           |  | +-+
|           |  `-' |
...        ...    ...

n = 12, d = 5    (output truncated!)

.-------------.
| 12:4096     |
|             |
| 000000000000|---+-----+-----+-----+-----+
|             |   |     |     |     |     |
|             |  .+.   .+.   .+.   .+.   .+.
|             |  | +-+ | +-+ | +-+ | +-+ | +-+
|             |  `-' | `-' | `-' | `-' | `-' |
...          ...    ...   ...   ...   ...   ...

what specifies the decoders width? From the examples it looks like its the width of the n:2^n + 2, but do we need to extend it when the gray node representation wouldn't fit in it (e.g. n=10, len(10:1024)+2 = 9, gray node repr length = 10)

Yes you'd need to extend it in that case, I'll add an example.

in that case, how should the decoder type be centered/anchored?

Anchored to the left, but with a space. See examples I added.

Summing up, the width would be max(len(n:2^n)+4,len(graycode)+3). The decoder name is always separated with one space from the left and the codes are right aligned without spaces.

SOGL V0.12, 185 bytes
b :2b^:D⁰∑l2+bIΧCc┌*:A .1ΟO@c*┐1Οd5*2+∙ `a '+++;31žƧ01bH{╬⁰1w⁄»Ƨ01*□+}I{∑4⌡@}¹cb-2+3žKOKOād0C{āe{"h}‼Τ─īsgQ⅛&šε╬»‘6n┌eF-¡3**41ž┐c3*∙ceF-*¡³ (*ž61ž┼}+1C}@5*┐+e*+d┌@4*Ο;┼øe∫eκƧd:ΚF6*1ž}+┼

Try it Here!
Way too long...

Well it's a fairly complicated pattern compared with other ASCII-art challenges, I think under 200 bytes is quite good. Unfortunately I couldn't test it for n > 8 but it looks good!

@BruceForte The sad thing is that 85 of the bytes is just the decoder box..

Charcoal, 170 157 bytes
ＮνＮδＡＸ²νηＡ⪫⟦θ:Ｉη ⟧ωθＡ⌈⟦νＬθ⟧ζ←“ E*lÿxγ∨P3ζgRＵ#@˜R2$⁴⟧”Ｆ⁻δ¹Ｃ±⁶¦⁰↓←|  Ｆ⁻η¹Ｃ⁰¦⁵Ｐ←×⁺+×-⁵δ⸿Ｐ|  ←Ｍ×⁵η↓Ｆδ«Ｐ⁺d:ιＭ⁶←»↑←'-←ζ↑`↑²↑×⁵η.-Ｐ⁺¶θζ↓.↓²Ｐ↓×⁵η←Ｆη«Ｆν←§0110÷ιＸ²κＭν⁵

Try it online! Verbose approximation. Explanation:
ＮνＮδＡＸ²νηＡ⪫⟦θ:Ｉη ⟧ωθＡ⌈⟦νＬθ⟧ζ

Sets up the variables used in the rest of the code. ν and δ are the inputs, η is 2ν, θ is the label at the top of the box, while ζ is one less than the width of the box.
←“ E*lÿxγ∨P3ζgRＵ#@˜R2$⁴⟧”

This compressed string represents the bottom left decoder. This is the one that's most representative, although ironically it first gets printed in the top right and then copied left and down.
Ｆ⁻δ¹Ｃ±⁶¦⁰↓←|

The decoder is repeated horizontally, and the --( at the top right of the last decoder is changed to a |.
Ｆ⁻η¹Ｃ⁰¦⁵Ｐ←×⁺+×-⁵δ⸿Ｐ|  ←Ｍ×⁵η↓

The decoder is then repeated vertically, and the (s in the top row are changed to -s (if you look carefully you'll see that too many -s are printed but fortunately the last one gets overwritten by the 0 of the address), after which the |s for the top right decoder are removed.
Ｆδ«Ｐ⁺d:ιＭ⁶←»

The decoders are numbered right-to-left.
↑←'-←ζ↑`↑²↑×⁵η.-Ｐ⁺¶θζ↓.↓²Ｐ↓×⁵η←

The box is printed, including the label.
Ｆη«Ｆν←§0110÷ιＸ²κＭν⁵

The Gray codes are printed.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Frankenstein Words
For this challenge you need to make a given word by concatenating "pieces" (a.k.a contiguous substrings) from other words. Given a word and a list of words as input, output the fewest number of pieces needed to create the first word.
Rules

Words consist of characters in the ASCII range 33 to 126.
The word list may have repeats.
Construction of words is case sensitive (you can not use the piece "Head" as part of the word "forehead".)
Once you have used a piece in a construction, you can not use any part of that piece again (e.g if I use "lo" from "lone" as part of constructing "lolo", I cannot use "lo" from that "lone" again. However, if I had two "lone" in my word list, I could use one "lo" from each.)
Once you use a piece, you can still make pieces out of unused substrings in the word. (E.g. If I used "tt" in "butter", I still have "bu" and "er" left over to use. However, I can't combine them into one "buer" piece.)
If it is impossible to construct the input word using the word list given, output nothing, or something other than a positive integer.

Examples
(you only need to output the number)

"snack" ["food","Shoe","snack"] => 1 (snack)
"Snack" ["food","Shoe","snack"] => 2 (S + nack)
"frog" ["cat","dog","log"] => 0
"~~Frank~~" ["Frog~","~~Love","Hank~"] => 4 (~~ + Fr + ank~ + ~)
"loop-de-loop" ["loop", "frien-d","-elk","pool"] => 7 (loop + -d + e + - + l + oo + p)
"banana" ["can","can","boa"] => 4 (b+an+an+a)
"banana" ["can","boa"] => 0
"13frnd" ["fr13nd"] => 3 (13 + fr + nd)

Let me know if you think of more useful test cases.

pieces are usually called contiguous substrings.

@Mr.Xcoder thanks, updated.

JavaScript, 209 206 bytes
f=(a,b,F)=>a?[...a].map((_,i)=>[...Array(i+1)].map((_,j)=>F||b.forEach((q,k)=>!F&&~(I=q.indexOf(a[S='substring'](j,r=a.length-i+j)))&&(F=b[k]=q[S](0,I)+' '+q[S](I+r+j),a=a[S](0,j)+a[S](r)))))&&F&&1+f(a,b):0

Try it online
Returns NaN if the combination is not found.


text:
Slowly converging zigzag
Given a single positive odd integer as input, return a converging zigzag as a list of strings, list of lists of characters, or newline-separated string, in this form:
#
 #
  #
   #
    #
   #
  #
 #
  #
   #
  #

You can replace # with any consistent non-whitespace character. Trailing whitespace on each line is allowed and a trailing newline is allowed.
The zig-zag starts at column 1 and for each row moves right one column, until it reaches column n (where n is the input). Then, it moves left to 2, then right to n-1, then left to 3, with the two bounds converging in until the zigzag ends in the middle column ((n+1)/2).
Test Cases
The example above is the test case for 5.
The following are individual test cases:
3
#
 #
  #
 #

7
#
 #
  #
   #
    #
     #
      #
     #
    #
   #
  #
 #
  #
   #
    #
     #
    #
   #
  #
   #
    #
   #

1

#

Is leading (but consistent i.e. not shape-breaking) whitespace allowed?

@EriktheOutgolfer I'm going to say no for that.

C (gcc), 89 bytes
f(n,a,b){puts("0");for(a=n;--a>n/2;)for(b=n-2*a;b<=2*a-n;)printf(" %*d\n",a-abs(b++),0);}

Try it online!
Works by analyzing the sequence of number of spaces as (for n=7):
          0
1 2 3 4 5 6 5 4 3 2 1
    2 3 4 5 4 3 2
        3 4 3

And for n=3:
  0
1 2 1

We can see that the middle number (a in the code) runs from [n-1, n/2). Then, the difference between the first number and the middle number is:
a  n  b  2a-n
-------------
6  7  5  5
5  7  3  3
4  7  1  1
2  3  1  1

So, if we have b going through [-(2a-n), 2a-n], a-abs(b) will give us the desired sequence. This is essentially what the code does.

Charcoal, 10 8 bytes
ＦＮ«↗ι‖»/

Try it online! Link is to verbose version of code. Edit: Saved 2 bytes thanks to @dzaima for pointing out that I don't have to use #s.

Finally, something that beats Jelly

Python 2, 78 bytes
l=range(1,input())
print 8
for i in l:
 for i in l:print' '*i+'8'
 l=l[-2::-1]

Try it online!

Haskell, 72 bytes
g[]=[]
g a=a++g(reverse$init a)
r="#":map(' ':)r
("#":).g.tail.(`take`r)

Try it online!
We define an infinite list r being the diagonal of #s starting from the upper left hand corner.
We then define a function g which does the brunt of the work.  g will take a list and repeatedly reverse it and remove its first element until the list is empty, then concatenate the result of each action.
Our main function here is a point-free function.  This function starts by taking n elements from the infinite list r, it then chops of the first element and applies g.  Last we have to add a # back to the beginning, this is because the specs for the question are a little weird, I'm not sure why the first diagonal is always one longer than it should be but, it is, so we have to add a a #.

@nimi I ended up doing ("#":).g.init.(taker) but thanks!

Jelly, 14 bytes
ṖṖṚ$ÐĿẎ0;⁶ẋp1Y

Try it online!
Full program.
Uses 1.
-1 thanks to Jonathan Allan.
-1 thanks to Jonathan Allan.

’R -> Ṗ for a byte.

@JonathanAllan Ooh of course thanks. I had tried to avoid it in an earlier verison and forgot it...

”X -> 1 for another.

@JonathanAllan Heh another overlook apparently...I tried to avoid integers too.

SOGL V0.12, 19 bytes
┘.»∫«I╝:±jk+jl0;±Iž

Try it Here!

05AB1E, 22 bytes
i8ë<LZFD¨R})˜0¸ìε8sú}»

Try it online!
Uses 8.

05AB1E, 6 bytes
LN71SΛ

Try it online!
     Λ     use the canvas function with

L          a range list [1 .. input] as lengths for each path

 N         a "0" as character to be printed
           (N is the index variable used by loops. If there was no loop yet, its
           default value is 0. By using N, I avoid an extra space between 0 and 71)

  71S      and the directions 7 and 1 (NW and NE), that alternate automatically until
           the range list is finished.

No, I tried that first, but it draws both directions, before it continues with the next element of the range list, when I remove the S. So the output will become twice as long. I didn't know about + and × yet. They make really interesting patterns when you combine them with numbers

Ah, you're indeed right. My bad. I saw it worked without the S, but didn't paid enough attention to the output.. >.> And the + and × are basically builtins for [0,4,4,0,2,6,6,2] and [1,5,5,1,3,7,7,3]. And 8 will reset to the origin where you started from. Here a bit more information.

Haskell, 74 bytes
f[x]=[x]
f s=s++tail(f$reverse$tail s)
g n=f[(' '<$[2..x])++"#"|x<-[1..n]]

Try it online!
How it works:
    [(' '<$[2..x])++"#"|x<-[1..n]]     -- build the first diagonal, e.g. for n=3:
                                         -- ["#", " #", "  #"]
  f                                      -- call f, which is

f s = s ++                               -- the input list, followed by
           tail                          -- all but the first element of
                f                        -- a recursive call with
                  reverse                -- the reverse of
                          tail s         -- all but the first element of the input
                                         -- list
f[x]=[x]                                 -- base case: stop if the input list a
                                         -- singleton list

Each recursive call to f appends the next diagonal.

Some friendly competition.

Husk, 19 bytes
mo`:'#R' ∫`Ṙ¢e1_1tṫ

Try it online!
Explanation
This feels a bit clunky.
mo`:'#R' ∫`Ṙ¢e1_1tṫ  Input is n (e.g. 5)
                  ṫ  Range from input to 1: [5,4,3,2,1]
                 t   Drop first element: [4,3,2,1]
             e1_1    The list [1,-1]
            ¢        repeated infinitely: [1,-1,1,-1,..
          `Ṙ         Clone with respect to the list above: [1,1,1,1,-1,-1,-1,1,1,-1]
         ∫           Cumulative sum: [0,1,2,3,4,3,2,1,2,3,2]
mo                   For each element k (e.g. 3) do this:
      R'             Repeat space k times: "   "
  `:'#               Append '#': "   #"
                     Print implicitly separated by linefeeds.

Python 3, 82 bytes
def z(n):l=range(1,n);print(8);exec("[print(' '*i+'8')for i in l];l=l[-2::-1];"*n)

Try it online!

Retina, 71 bytes
.+
$*
^
:>
 $
:
;{*T`:<>`_#
( ) >(:)|( )<
$1<$2$3
(:)( )<|>( )
$2$1$3>

Try it online! Explanation: The first three stages convert the input into the form :>     : where the number of characters between the :s is the input number. The last two stages then bounce the > (or <, when moving leftward) between the :s. The fourth stage loops the bounce, printing the required parts of the string each time. The ; stops the string from being printed after the loop.

05AB1E, 16 bytes
Î<L¤FÂ¦})˜Ôð×X«»

Try it online!
Explanation
Î<L               # push 0 and range [1 ... input-1]
   ¤              # get the last element of the list
    F             # that many times do
     Â            # bifurcate
      ¦           # remove the head
       })˜        # end loop and wrap in flattened list
          Ô       # remove consecutive duplicates
           ð×     # repeat space a number of times corresponding to each number in the list
             X«   # append 1 to each
               »  # join on newline

K (Kona), 27 bytes
`0:{|x$"#"}'1,,/{1_|x}\-2-!

Produces the underlying numeric sequence by repeatedly reversing and dropping the head of a vector until empty.

Welcome to PPCG.SE! Just so you know, you can put your code into an online interpreter called TIO (Try it online) and link to it so people can try your code. https://tio.run/#k-kona it will even provide you with a formatted PPCG post for you to submit here.

CJam, 29 bytes
ri,(;_,{_);W%}*]e_0\+Sf*8f+N*

Try it online!
Uses 8.

JavaScript, 127 bytes
Calculates the goal (g) to get to. When this goal is reached, turn around to the next goal. Also uses a trick to avoid using Math.round() by adding 0.5 to every uneven number.
f=n=>{c=0;for(i=0;i<n;i++){m=i/2;g=i%2==0?n-m:m+1.5;while(c!=g){c>g?c--:c++;console.log(' '.repeat(c-1)+'#'+' '.repeat(n-c))}}}

f=n=>{c=0;for(i=0;i<n;i++){m=i/2;g=i%2==0?n-m:m+1.5;while(c!=g){c>g?c--:c++;console.log(' '.repeat(c-1)+'#'+' '.repeat(n-c))}}}

f(5);

Pyth, 23 bytes
8JStQKdVQjbm+*\ d8J=_PJ

Try it here.

Japt, 31 bytes
Ç+V ç +QÃê ¯-2 c´U?ß´UVÄ :Vç +Q

Recursive solution that returns an array of lines.
Try it online! using the -R flag to join output with newlines.

Mathematica, 142 102 bytes (independent)
This solution has a mathy flavor:
UnitVector[#,1-Sum[(-1)^Floor[#+1/2-Sqrt[9/4+#*#-#-2x]],{x,k}]]~Table~{k,0,#(#-1)/2}/.{0->" ",1->"X"}&
This basically calculates which segment we're in (by inverting the triangular number function) and then moving left or right by adding a power of -1.
You can test it on the Wolfram Code Sandbox by pasting code like UnitVector[#,1-Sum[(-1)^Floor[#+1/2-Sqrt[9/4+#*#-#-2x]],{x,k}]]~Table~{k,0,#(#-1)/2}/.{0->" ",1->"X"}&@6//MatrixForm and pressing Shift+Enter or Numpad Enter or clicking Gear->"Evaluate Cell".

This happens to be the same length as my original incorrect port of Erik's Python 2 solution (This port gives the output for an input one higher):
(Print[X];l=Range@#;Do[Do[Print[StringRepeat[" ",l[[j]]]<>"X"],{j,Length@l}];l=l[[-2;;1;;-1]],{i,#}])&

Python 2, 159 145 141 136 bytes
print"".join([" "*p+"#\n"for p in(lambda l:[sum(l[:i])for i in range(len(l))])(sum([i*[1-i%2*2]for i in range(input())[::-1]],[])+[1])])

There has already been quite nice Python versions to this problem but I thought I'd still post my awful one-liner. (Without semicolons though!)
Edit: 14 bytes down, using sum instead of double list comprehension
Edit: Just noticed in python 2 you can use input instead of raw_input.
I've always just used the latter.

PHP, 65 bytes
<?while(--$n||$n=$d=--$argn)echo str_pad("X
",2+$x-=$d&1?:-1);?>X

Run as pipe with -nF or test it online.
explanation:
first iteration: $n is NULL, so --$n has no effect and evaluates to NULL
--> set $n and $d to pre-decremented argument
1. increment $x for even $d, decrement for odd $d
2. print X, a newline and $x spaces
further iterations: decrement $n; when it hits 0, reset $n (and $d) to pre-decremented argument
finale: print one more X.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/