# 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? 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 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. 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?
May 7 '17 at 21:50
• @SteveBennett Why haven't you made that challenge yet? 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  # 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. # 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? 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 :) 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? 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. Jun 7 '17 at 22:59 • @MDXF I never thought about my username this way! No, its origin is totally unrelated to the pic :-) 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. # Malbolge, 32 bytes invalid character in source file  Try it online! # Piet, using npiet interpreter cannot read from Error.txt'; reason: unknown PPM format  Save as 'Error.txt' and put it in the same folder as the npiet executable. If you want to golf, you can of course choose a shorter filename and adjust the code to match. • Glad someone else thought of Piet. I really want to make my own image-based esolang some day. Jan 28 at 15:59 # 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? 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. 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! Python 3, 28 bytes SyntaxError: invalid syntax  # Triangularity, 46 bytes I smell no triangularity. YOU SHALL NOT PASS!  Try it online! The language requires programs to be in the form of a triangle. If not, it denies you the gate to programming in the world of triangles. It will not let you pass. # 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 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? 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. 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. 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. 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


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

# 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 Jan 24 '17 at 6:41
• I had that first, but this is a popularity-contest, so I went with something more creative. 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).

# 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" Jun 13 '18 at 13:26
• This seems to be an error message as far as I can tell. It does output to STDERR afterall. Dec 16 '20 at 23:15

# 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


# Pip, 71 bytes

code and error:

R is not a unary operator
Fatal error while parsing, execution aborted.


also:

Hit end of tokens while parsing expression
Fatal error while parsing, execution aborted.


Try it online!

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

# Rust v1.45.2 (via Rust Playground)

Code (1126 bytes):

error: unknown start of token:
--> src/lib.rs:1:32
|
1 | error: unknown start of token: 
|                                ^
|
help: Unicode character '' (Grave Accent) looks like ''' (Single Quote), but it is not
|
1 | error: unknown start of token: '
|                                ^

error: unknown start of token: 
--> src/lib.rs:4:36
|
4 | 1 | error: unknown start of token:
|                                    ^
|
help: Unicode character '' (Grave Accent) looks like ''' (Single Quote), but it is not
|
4 | 1 | error: unknown start of token: '
|                                    ^

error: character constant must be escaped: '
--> src/lib.rs:7:56
|
7 | help: Unicode character '' (Grave Accent) looks like ''' (Single Quote), but it is not
|                                                        ^

error: unterminated character literal
--> src/lib.rs:9:36
|
9 | 1 | error: unknown start of token: '
|                                    ^

error: aborting due to 4 previous errors

error: could not compile playground.


Try it online (error message might differ in future versions of the language, though)

Compile errors in Rust all start with "error:", so copy/pasting the errors into the source a bunch of times eventually leads to these error messages. Default settings for the Rust Playground were used. That means 2018 edition, stable branch, and debug mode. I don't know what the target triple is.

## Setanta, 97 bytes

Eisceacht ar líne 1: Suíomh 19: Ag súil le uimhir, téacs, bool, athróg, liosta, nó gníomh.


Try it here!

# m4 (before 1.4.18-3 Termux patch), Termux, Android 11, 35 bytes

Who said the error had to be caused directly?

FORTIFY: %n not allowed on Android



Includes trailing newline.

m4 uses a very old version of Gnulib.

Since Android doesn't support %n in printf, Gnulib will replace every printf function in libc with its own custom implementation.

However, stupidly, said function will still use libc's snprintf function internally (which it is supposedly trying to replace because it doesn't work 🤔), and when using it, it attempts to use %n every single time it is called, even if %n isn't in the original format string.

%n used to be silently ignored on Android (similar to macOS), but Android 11 made these errors fatal, causing this error to be printed followed by abort().

I used set +m to prevent Bash from printing the signal error, and I had to compile from source to undo the -3 patch.

The file itself doesn't matter: m4 is guaranteed to crash no matter what. This includes running with no arguments.

See this Github issue