# Make an error quine!

Your challenge: write a "program", for a language of your choice, that causes the compiler/interpreter/runtime to produce error output when compiling/running your program which is identical to your program's source code.

Rules:

• Your program may be specific to a particular version or implementation of your language's compiler/interpreter/runtime environment. If so, please specify the particulars.
• Only standard compiler/interpreter/runtime options are permitted. You cannot pass some weird flag to your compiler to get a specific result.
• The program does not need to be syntactically or semantically valid, but I may give a bounty to the best syntactically valid submission.
• The program must not produce any output of its own (e.g. by calling a print or output function). All output generated upon attempting to compile/run the program must originate from the compiler/interpreter/runtime.
• The complete output of the compiler/interpreter/runtime must be exactly identical to your program source code.
• The compiler/interpreter/runtime must generate at least one error message when invoked with your program.

This is a popularity contest. Most creative answer, as determined by upvotes, wins. If you can give a good case for using a standard loophole, you may do so.

• What is "error output"? And what does it mean to "generate an error message"? More specifically: 1) Does the output have to be to stderr? 2) If the runtime logs an error to syslog and doesn't write anything to stderr, what should be compared to the source of the program? 3) If the runtime throws an exception internally when given an empty program, but requires a flag to actually print the exception and so ends up exiting with a non-zero exit code but no output, has an error message been generated? – Peter Taylor Aug 16 '14 at 9:24
• I tried doing this in java and got a p3 oscilator. This was the shortest phase: (Compile from q.java): Error: Could not find or load main class Q – SuperJedi224 Jun 1 '15 at 12:57
• Ha, because of a syntactic ambiguity in the first sentence, I thought the challenge here was to produce a program which normally produces no output, but if you pass its own code to it as input, it produces an error. – Steve Bennett Apr 10 '17 at 6:32
• When reporting an error, APL always prints a customizable error name, optionally an error message, the name of the program that caused the error, the (bracketed) line number where the error occurred, the line of code that caused the error, and a line with a caret indicating where parsing stopped. Any hope for participation here? – Adám May 7 '17 at 21:50
• @SteveBennett Why haven't you made that challenge yet? – CalculatorFeline May 28 '17 at 1:53

# Forth

Try it here

This was surprisingly easy to come up with.

a : error(-13): word not found


# zsh (Linux)

zsh: command not found: zsh:

Should work with some small changes in just about any other shell.

# Bash

$bash: bash:: command not found bash: bash:: command not found  # GNU Make 4.1 make: *** No rule to make target 'No', needed by 'make'. Stop.  This is syntactically valid: • Make tries to evaluate the target named make (first target is the default), • which depends on the target named No, • which it has no rule for. • But don't ***, 'No', and Stop. contain syntactically invalid tokens? Also, have you noticed that your profile shows a picture of someone rushing but your name is eush77? – MD XF Jun 7 '17 at 21:30 • @MDXF Oh, no. *** is a wildcard, 'No' is quoted, and the dot in Stop. is allowed (as in filenames, e.g. Stop.c). You can run make --debug to see for yourself that it proceeds exactly as I described. You can also touch No to see the message change :) – eush77 Jun 7 '17 at 22:42 • @MDXF I'm sorry, I didn't get the joke about rushing and the first letter of my name. Is it somehow unusual on this site? – eush77 Jun 7 '17 at 22:48 • Ah, okay. +1 and I didn't mean for it to be a joke; I thought you may have had a typo in your username. My bad. – MD XF Jun 7 '17 at 22:59 • @MDXF I never thought about my username this way! No, its origin is totally unrelated to the pic :-) – eush77 Jun 7 '17 at 23:25 # x86 assembly Bytecode: 53 65 67 6d 65 6e 74 61 75 69 6f 6e 20 66 61 75 6c 74 20 28 63 6f 72 65 20 64 75 6d 70 65 64 29  i.e. the text Segmentation fault (core dumped)  Crashes immediately because the second instruction (the first being just "push %[er]bx") is insl (%dx), %gs:(%di)  which fails because (a) ins cannot take segment overrides, (b) %dx and %di are almost certainly uninitialized, (c) %di is a 16-bit memory address and therefore can't be accessed in long mode, (d) ins is an invalid instruction outside of real mode. The exact output may vary depending on what system this is run on, but it is likely that it will contain some form of illegal instruction. # Lua Code: lua: ERROR.lua:1: function arguments expected near '.'  It seems fairly easy to do with lua. I also modified it to work on ideone.com as: luac: prog.lua:1: function arguments expected near '.'  Try it. • Yeah, got it in few iterations starting from single local. Won't you mind if I'll explain this in answer's body? – val says Reinstate Monica Jul 19 '19 at 17:51 # Rebol Interestingly, the error message here parses as symbols/tokens: x ** Script error: x has no value ** Where: do either either either -apply- ** Near: do intern code  So despite looking error-like, it could be made a valid Rebol program if you gave all the words meanings. However if you wanted an error at the parse phase vs. a runtime error in the code, the program/error could be: 1A ** Syntax error: invalid "integer" -- "1A" ** Where: to case load either either -apply- ** Near: (line 1) 1A  So given that distinction is possible, you can do fun things if you redefine ** from exponentiation into something else (which I can't think of how to make useful for this particular challenge, given it's a quine.) (Note: Trying to abuse it for a trick uncovered a peculiarity of what happens when ** (an infix operator) is redefined and then used immediately after. I tried: **: function [:a :b :c :d :e :f] [] ** Syntax error: invalid "integer" -- "1A" ** Where: to case load either either -apply- ** Near: (line 1) 1A  My goal was to override the ** so that it would accept its arguments unevaluated. That way ** Syntax error: invalid "integer" -- "1A" (or whatever) would not attempt to assign invalid to error, but pass the symbols to **. But because ** is infix it attempted to raise the function body to the power of Syntax prior to the completion of the assignment of **:. It can be remedied by putting any token between the [] and the **. But it helps to remember how your language evaluator works. :-P) ## R (GUI) Error: unexpected symbol in "Error: unexpected symbol"  The issue here is replicating the ", which causes the error message to change from unexpected symbol to unexpected string constant. Pretty much any error R throws will have the form Error: <something> in "<bad code>", so you will pretty much always have to contend with the quoting. I tried this several other ways and always ended up falling back here. # ArnoldC, 28 bytes WHAT THE FUCK DID I DO WRONG  This is the only error message in ArnoldC, though you do have to turn off stack traces. Pyth  s_push: parser stack overflow Traceback (most recent call last): File "pyth.py", line 752, in <module> exec(code_to_remove_tools + py_code_line, environment) MemoryError  Try it online! # Malbolge, 32 bytes invalid character in source file  Try it online! # Go Another fairly easy one using the "general approach" provided in the other answer. I still like my JavaScript ones better. can't load package: package : prog.go:1:1: expected 'package', found 'IDENT' can prog.go:2:2: invalid package name _  Try it. ## Lua (console), 35 bytes This is what you get in the Lua console with the usual iterative approach: stdin:1: '<name>' expected near '1'  which is a bit shorter than the one obtained for putting the code in a file. # ksh $ ksh: ksh::  not found.

• Also works with bash: bash: bash:: comand not found – Shelvacu Aug 20 '14 at 0:54
• @shelvacu on my build of bash, bash: command not found errors with bash:: command not found, which errors with bash::: command not found. Am I doing something wrong? – clapp Nov 2 '15 at 15:25
• @ConfusedMr_C must be a case of different versions. I am running 4.3.042-3 on x64 Arch Linux, and it works. – Shelvacu Nov 3 '15 at 5:42
• @shelvacu I'm running x64 Ubuntu, with whatever version of bash came with Ubuntu 14.04.3. Also, you can do zsh: command not found: zsh: in zsh. – clapp Nov 3 '15 at 23:41
• @shelvacu Sorry, I just found out, I'm using 4.3.11(1)-release on x64 Ubuntu 14.04.3. – clapp Nov 6 '15 at 7:21

# Perl

syntax error at quine.pl line 2, at EOF
Execution of quine.pl aborted due to compilation errors.


Replace quine.pl with whatever you named the file and enjoy.

• Is it even possible to have a syntax error in perl? From what I've read online (mainly here) it seems as though perl accepts anything? – user63571 Jan 28 '17 at 0:27

# Java, in Eclipse

Syntax error on tokens, delete these tokens


# SmileBASIC

NEXT without FOR in 0:1


Whenever the pre-run parser encounters a NEXT which isn't paired with a FOR, it produces the error NEXT without FOR in slot:line. Here, the code is in slot 0 and on line 1.

• Syntax error in 0:1 is shorter – 12Me21 Jan 24 '17 at 6:41
• I had that first, but this is a popularity-contest, so I went with something more creative. – snail_ Jan 24 '17 at 12:08

# (t)csh

Unmatched '.



The trailing newline is needed to produce an exact match. Run it with csh quine.csh (or just type it into the shell, that works too).

Python 3, 28 bytes

SyntaxError: invalid syntax


# Javascript (Chrome/V8), 6541 39 Bytes

Uncaught =u=_=>{throw=u=\${u};u()};u()


Try it online!

# Rust, 323166 164 bytes

Call your program a. and use rustc a..

error: unknown start of token: \
--> a.:1:32
|
1 | error: unknown start of token: \
|                                ^

error: aborting due to previous error


# TI-83/84 Basic

ERR:SYNTAX

• Doesn't work. Even if it did, it would be missing the 1:Quit\n2:Goto. – lirtosiast Sep 1 '15 at 1:44

# Factor

No word named "No" found in current vocabulary search path


Guess what it prints?

No word named "No" found in current vocabulary search path


# Processing IDE

Probably the friendliest error message I've ever seen.

Syntax error, maybe a missing semicolon?


### Result

Technically this is cheating a bit because the pane below it prints expected SEMI, found 'error'. Unfortunately the word error is written in single quotes, so trying to copy that into the source of the program causes it to spit out a massive "Badly formed character constant" error... which does not include any singly-quoted words allowing for it to quine itself.

# MATLAB, 66 bytes

Undefined function 'Undefined' for input arguments of type 'char'.


This outputs the same to STDERR (shown in the console in red):

This is actually pretty unknown functionality (and it's rarely useful), which is why the MATLAB submission in the "Hello World!"-challenge may be improved.

This works because MATLAB will automatically interpret a command on the form <word_1 word_2 word_3 word_4>, with no surrounding brackets, as a function on the form:

word_1('word_2')


That is, it calls a function word_1 and gives the single input argument after the first, and in front of the second space as a string input to that function.

"Real life"-examples that can be used for golfing:

disp Hello   % Shorter than disp('Hello')
Hello

disp Hello World!
Hello

nnz variable
ans =
8


Note that it will always interpret it as a string, it will not evaluate it:

variable = 3;
nnz variable
ans =
8
nnz(variable)
ans =
1

• In my current MATLAB version (R2016b), this can be considerably shortened to 43 bytes: Undefined function or variable 'Undefined'.. – Sanchises Jun 13 '17 at 9:20
• Really, it doesn't treat the words after Undefined as string inputs? What happens if you do Undefined('function','or','variable')? In previous versions these commands are equivalent. It doesn't tell you that the character input is invalid? It makes sense, but it's definitely new behavior. What about a=2;b={};a(b). Or just a({1}) without initializing anything first? – Stewie Griffin Jun 13 '17 at 9:26
• It does, hence "function or variable". However, I think the old error message was misleading, because 'Undefined' does not have to be a function, but could indeed be a variable, and many (most) functions are defined for arbitrary input, seeing as there is no native way that I know of to define a function like y=f(uint32 x), so saying that a function is not defined for 'char' does not make sense. – Sanchises Jun 13 '17 at 9:36
• As for your examples: Undefined('function','or','variable') returns Undefined function or variable 'Undefined'. (indeed, you could be indexing into the variable Undefined); the latter two examples give Function 'subsindex' is not defined for values of class 'cell'. – Sanchises Jun 13 '17 at 9:38
• I agree, the new behavior makes more sense than the old one... I'm just surprised that they changed it. It makes this slightly outdated. – Stewie Griffin Jun 13 '17 at 10:01

# Cubically, 94 bytes



000
000
000
111222333444
111222333444
111222333444
555
555
555



There are newlines at the start and end. (Cubically automatically dumps its memory to STDERR when the program finishes.)

Try it online!

• Technically this isn't an error. so it does not "generate at least one error message" – ASCII-only Jun 13 '18 at 13:26

# A Pear Tree

a partridge



Try it online!

Almost every program (that isn't very long) prints a partridge in A Pear Tree.

One of the goals of the language was to be good at challenges; as such, it tries to find a substring of the program that has a very specific property that rarely occurs by chance, and starts running the program there. If it can't find an appropriate entry point, it prints an error. The actual text of the error message was chosen for the The Twelve Days of Christmas reference. (Actually, the design for the language worked the other way round; the main goal was to have a language which errored out on almost any source code, so that it would make the reference in question, so I set about trying to work out what sort of language design would naturally end up doing that.)

# Cobra

test.cobra(1): error: Expecting use, assembly, namespace, class, interface or enum, but got "test".
Compilation failed - 1 error, 0 warnings
Not running due to errors above.


# Befunge on Wasabi v1.4

There is an interpreter for Befunge called Wasabi, and when an error appears the error message is in the format of a dialog box. This is the program:

Unsupported Command : 'U' at (1, 0). Ignore next syntax error(s)?


Unknown type name 'Unknown'
`