125
\$\begingroup\$

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.

\$\endgroup\$
7
  • 9
    \$\begingroup\$ 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? \$\endgroup\$ Aug 16, 2014 at 9:24
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ Jun 1, 2015 at 12:57
  • 3
    \$\begingroup\$ 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. \$\endgroup\$ Apr 10, 2017 at 6:32
  • 2
    \$\begingroup\$ 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? \$\endgroup\$
    – Adám
    May 7, 2017 at 21:50
  • 1
    \$\begingroup\$ @SteveBennett Why haven't you made that challenge yet? \$\endgroup\$ May 28, 2017 at 1:53

131 Answers 131

1
\$\begingroup\$

K (ngn/k), 2 bytes

'c

Try it online!

'c is the response from the console indicating that the variable c is undefined

\$\endgroup\$
1
  • \$\begingroup\$ Apologies, I've edited, thought what I was getting was STDERR as I was operating in the console and saw the output replicated by oK in TiO \$\endgroup\$
    – Thaufeki
    Oct 11, 2018 at 17:29
1
\$\begingroup\$

MiLambda

ERROR_NOHALT

Try it online!

Seems like a short solution

\$\endgroup\$
1
\$\begingroup\$

Turing Machine But Way Worse, 258 bytes

Traceback (most recent call last):
  File "/opt/tmbww/TuringMachineButWayWorse.py", line 16, in <module>
    i[0], i[2], i[3], i[5], i[6] =  int(i[0]), int(i[2]), int(i[3]), int(i[5]), int(i[6])
ValueError: invalid literal for int() with base 10: 'Traceback'

Try it online!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ The rule about languages postdating the challenge has been abolished, you can compete all you want. \$\endgroup\$ Mar 22, 2019 at 0:51
  • \$\begingroup\$ @ØrjanJohansen Oh, okay \$\endgroup\$
    – MilkyWay90
    Mar 22, 2019 at 1:04
1
\$\begingroup\$

ZSH (macOS), 20 bytes excluding newline

 zsh: bad pattern: ^[
\$\endgroup\$
1
  • 1
    \$\begingroup\$ all error messages should include this: : ^[ \$\endgroup\$
    – roblogic
    Aug 23, 2019 at 5:06
1
\$\begingroup\$

Ly

Error occurred at program index 3, instruction o (zero-indexed, includes comments)
EmptyStackError: cannot pop from an empty stack

Demo (using official compiler)

This program makes use of the o in "Error", the first instruction character in the error message that produces an error. (apparently r does nothing with an empty stack)

When a stack is not empty, o takes the top entry off the selected stack and outputs it as ASCII; EmptyStackError occurs when the selected stack is empty. So when Ly runs into this o, it causes this error, since we haven't given the stack anything yet.

\$\endgroup\$
1
\$\begingroup\$

W.Y.A.L.H.E.I.N., 253 bytes

Traceback (most recent call last):
  File "/opt/wyalhein/whenyouaccidentallylose100endorsementsinnationstates.py", line 6, in <module>
    seed = int(contents[0])
ValueError: invalid literal for int() with base 10: 'Traceback (most recent call last):\n'

Try it online!

whenyouaccidentallyloseahundredendorsementsinnationstates expects a seed on the first line, and Traceback (most recent call last): is not a valid number (unless we're talking in base 96, of course, but whenyouaccidentallyloseahundredendorsementsinnationstates doesn't).

\$\endgroup\$
2
  • \$\begingroup\$ You kinda get screwed by the length of the language name huh? \$\endgroup\$
    – Jo King
    Jun 18, 2019 at 2:56
  • \$\begingroup\$ @JoKing Yeah. It was even shortened on TIO because the name was too long \$\endgroup\$
    – MilkyWay90
    Jun 18, 2019 at 2:58
1
\$\begingroup\$

Loader (using the official Java interpreter):

These should be run from a module named main in order to produce the exact error messages given here.

This works in the most recent version of the interpreter:

Error: Could not evaluate expression Error (module main, line 1)

Explanation:

expression:statement is a conditional. The interpreter doesn't even syntax check the stuff to the right of the colon (if it did, we'd get a different error message) unless the stuff on the left evaluates to a nonzero value. However, as "Error" is an illegal expression, the interpreter can't evaluate it, exiting the program with this error message.

In some earlier interpreter versions, this would work instead:

Exception in thread "main" java.lang.RuntimeException: Could not evaluate expression Exception in thread "main" java.lang.RuntimeException (module main,line 1)
    at Loader.expr(Loader.java:183)
    at Loader.load(Loader.java:201)
    at Loader.main(Loader.java:249)
\$\endgroup\$
1
\$\begingroup\$

ESOPUNK, 38 bytes

Invalid instruction INVALID at line 0.
\$\endgroup\$
2
  • \$\begingroup\$ Wasn't this posted after the postdated language consensus was changed? \$\endgroup\$
    – ASCII-only
    Jan 20, 2019 at 6:15
  • \$\begingroup\$ No idea, to be honest. I'm not exactly in the race for anything, though, so I'm not particularly worried. \$\endgroup\$ Jan 24, 2019 at 23:37
1
\$\begingroup\$

C (tcc), 42 bytes

.code.tio.c:1: error: declaration expected

Try it online!

\$\endgroup\$
1
\$\begingroup\$

MS SQL (Server version 2012), 64 bytes

Msg 2812, Level 16, State 62, Line 1
Incorrect syntax near '16'.
\$\endgroup\$
1
\$\begingroup\$

Julia 1.0 (Tio)

Implementation specific, but this one is made to run in Tio.

ERROR: LoadError: UndefVarError: syntax: extra token "token" after end of expression
Stacktrace:
 [1] include at ./boot.jl:317 [inlined]
 [2] include_relative(::Module, ::String) at ./loading.jl:1038
 [3] include(::Module, ::String) at ./sysimg.jl:29
 [4] exec_options(::Base.JLOptions) at ./client.jl:229
 [5] _start() at ./client.jl:421
in expression starting at /home/runner/.code.tio:1

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Brain-flak

Error at character 33: Unclosed '(' character.

Try it online!

Haskell

[1 of 1] Compiling Main             ( .code.tio.hs, .code.tio.o )

.code.tio.hs:1:4: error: parse error on input ‘of’
  |
1 | [1 of 1] Compiling Main             ( .code.tio.hs, .code.tio.o )
  |    ^^
/srv/wrappers/haskell: line 5: ./.bin.tio: No such file or directory

Try it online!

Stack Cats

Error: invalid character in source code, E | E ,edoc ecruos ni retcarahc dilavni :rorrE

Try it online!

Taxi

error: parse error: likely incomplete statement

Try it online!

Hexadecimal Stacking Pseudo-Assembly language

/opt/hspal/hspal.rb:69:in `run': Illegal opcode: 170  (RuntimeError)
    from /opt/hspal/hspal.rb:75:in `<main>'

Try it online!

Quarterstaff

Traceback (most recent call last):
  File "/opt/quarterstaff/quarterstaff.py", line 142, in <module>
    QuarterstaffInterpreter(open(parser.parse_args().program).read())
  File "/opt/quarterstaff/quarterstaff.py", line 7, in __init__
    self.run(self.parse(program), {}, 0)
  File "/opt/quarterstaff/quarterstaff.py", line 35, in parse
    raise Exception
Exception

Try it online!

Haxe

Main.hx:1: characters 0-4 : Unexpected Main
Uncaught exception - load.c(181) : Module not found : .bin.tio

Try it online!

Hasm

Error with instruction <internal{PARSE}> on line 0:
    Syntax error or illegal instruction: Error with instruction <internal{PARSE}> on line 0:
Dumping core:


STACK:
    
OFFSTACK:
    
HEAP:
    0 

Try it online!

Mornington Crescent

Traceback (most recent call last):
  File "/opt/mornington-crescent/esoterpret.py", line 123, in <module>
    arguments.stdin, extra)
  File "/opt/mornington-crescent/esoterpret.py", line 41, in use_language
    while not(interpreter.has_execution_finished()):
  File "/opt/mornington-crescent/modules/morningtoncrescent/morningtoncrescent.py", line 50, in has_execution_finished
    raise RuntimeError("You have to end at Mornington Crescent.")
RuntimeError: You have to end at Mornington Crescent.

Try it online!

Muriel

*** ERROR: muriel: Unknown token '*'

Try it online!

Just picked some random esolangs from TIO and keyboard hashed until I got an error, then copy + pasted.

\$\endgroup\$
1
\$\begingroup\$

Phooey, 21 bytes

Unknown mode for '$'

Try it online!

Phooey ignores Unknown mode for ', then tries to parse $' which is an unknown mode for $. 😂

\$\endgroup\$
1
1
\$\begingroup\$

Knight (v2 + EVAL) (knight-lang.netlify.app implementation), 32 bytes

Error: Unknown identifier 'rror'

Try it online!

Different implementations handle errors differently (it is undefined behavior in the official specs), which is why I specified the implementation that I'm using.

Also, this technically only works in version 1.x because EVAL is removed as a required function in the v2 official specs, but this implementation has EVAL even though it is a v2 implementation, which is why I specified EVAL in the header just to be safe.

If EVAL wasn't implemented in this implementation, I think something like Error: No value could be parsed! would be a valid error quine instead (and it coincidentally turns out to also be 32 bytes).

Knight (v1.2) (C (gcc) implementation), 21 bytes

invalid character 'i'

Try it online!

Different implementation, different error messages :)

\$\endgroup\$
1
\$\begingroup\$

Fig, 1292 bytes (UTF-8)

DEBUG:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "x" is null
    at clojure.lang.Numbers.ops(Numbers.java:1068)
    at clojure.lang.Numbers.incP(Numbers.java:141)
    at fig.compression$fromBijectiveBase$fn__191.invoke(compression.clj:26)
    at clojure.core.protocols$fn__8181.invokeStatic(protocols.clj:168)
    at clojure.core.protocols$fn__8181.invoke(protocols.clj:124)
    at clojure.core.protocols$fn__8136$G__8131__8145.invoke(protocols.clj:19)
    at clojure.core.protocols$seq_reduce.invokeStatic(protocols.clj:31)
    at clojure.core.protocols$fn__8168.invokeStatic(protocols.clj:75)
    at clojure.core.protocols$fn__8168.invoke(protocols.clj:75)
    at clojure.core.protocols$fn__8110$G__8105__8123.invoke(protocols.clj:13)
    at clojure.core$reduce.invokeStatic(core.clj:6830)
    at fig.compression$fromBijectiveBase.invokeStatic(compression.clj:26)
    at fig.compression$decompress.invokeStatic(compression.clj:39)
    at fig.compression$decompress.invoke(compression.clj:35)
    at fig.compression$decompress.invokeStatic(compression.clj:36)
    at fig.parsing$lex.invokeStatic(parsing.clj:40)
    at fig.core$_main.invokeStatic(core.clj:38)
    at fig.core$_main.doInvoke(core.clj:19)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at fig.core.main(Unknown Source)

Try it online!

The tabs sadly disable Fig's scoring system, so this is counted in UTF-8/ASCII. Still no normal Fig quine...

\$\endgroup\$
1
1
\$\begingroup\$

gpg (GnuPG) 2.2.40, 157 bytes

Note error is followed by a newline.

gpg: WARNING: no command supplied.  Trying to guess what you mean ...
gpg: no valid OpenPGP data found.
gpg: processing message failed: Unknown system error

Usage in shell

I don't know if that source is REALLY a program source.

cat <<'X' >source
gpg: WARNING: no command supplied.  Trying to guess what you mean ...
gpg: no valid OpenPGP data found.
gpg: processing message failed: Unknown system error
X
gpg <source >stdout 2>stderr
cat stdout
diff source stderr
\$\endgroup\$
1
\$\begingroup\$

ACCUMULATOR, 7 bytes

Invalid

Invalid is the only error in ACCUMULATOR. This is because I is not a function in ACCUMULATOR.

\$\endgroup\$
1
\$\begingroup\$

xidoc, 66 bytes

Error while rendering file 
at 2:17-2:18 in []
Command not found: 

xidoc, 135 bytes

Error while rendering file 
at 3:26-3:26
Parse error: Unexpected ']'
3 │ Parse error: Unexpected ']'
  │                          ^

Try it (you need to paste in the code)

\$\endgroup\$
1
\$\begingroup\$

Python 3 (IDLE)

SyntaxError: incomplete input

This surprisingly outputs just itself and nothing else.

\$\endgroup\$
6
  • 3
    \$\begingroup\$ What Python version are you using? Python 1, 2, and 3 all throw a SyntaxError: invalid syntax here for me \$\endgroup\$
    – emirps
    May 3, 2023 at 18:12
  • \$\begingroup\$ It outputted this in the IDLE shell… try in python 3.8 prerelease or python 3.11 @emirps \$\endgroup\$ May 3, 2023 at 18:33
  • 1
    \$\begingroup\$ the IDLE has different output than the python interpreter, but this answer can be an answer in “Python IDLE” if that is what it outputs \$\endgroup\$
    – emirps
    May 3, 2023 at 18:43
  • \$\begingroup\$ Can confirm I get "SyntaxError: invalid syntax" on 3.8 (pre-release) as well on TIO tio.run/##K6gsycjPM7YoKPr/P7gyrySxwrWoKL/ISiEzLzk/… \$\endgroup\$
    – mousetail
    May 3, 2023 at 18:43
  • \$\begingroup\$ It seems to work in IDLE, even on 3.11 though, so if you change your language to "Python 3 (IDLE)" this would be valid. \$\endgroup\$
    – mousetail
    May 3, 2023 at 18:45
1
\$\begingroup\$

MirBSD pax, 127 bytes.

Includes trailing newline:

pax: End of archive volume 1 reached
pax: Cannot identify format. Searching...
pax: Sorry, unable to determine archive format.

Usage

$ pax -f quine 
pax: End of archive volume 1 reached
pax: Cannot identify format. Searching...
pax: Sorry, unable to determine archive format.
$ pax < quine 
pax: End of archive volume 1 reached
pax: Cannot identify format. Searching...
pax: Sorry, unable to determine archive format.
$
\$\endgroup\$
1
\$\begingroup\$

(,) 38 Bytes

code must be surrounded by parentheses

Litterally the only possible one on my current interpreter

\$\endgroup\$
1
\$\begingroup\$

Applescript, 70 bytes

0:2: syntax error: A “:” can’t go after this identifier. (-2740)

Run with osascript -e "0:2: syntax error: A “:” can’t go after this identifier. (-2740)"

\$\endgroup\$
1
\$\begingroup\$

YASEPL

ERROR 5 no variable is loaded:(

located at :

very simple

\$\endgroup\$
1
\$\begingroup\$

LOLCODE, 43 bytes

.code.tio:1: unknown token at: .code.tio:1:

Try it online!

Uiua, 95 bytes SBCS

Error: Unexpected token |
  at 1:25
1 | Error: Unexpected token |
                            ─

Try it online!

\$\endgroup\$
0
\$\begingroup\$

CJam, 12 bytes

u not handled

When operator doesn't exist, interpreter prints * not handled

\$\endgroup\$
1
0
\$\begingroup\$

Elixir

== Compilation error on file e.ex ==
** (SyntaxError) e.ex:3: keyword argument must be followed by space after: ex:
    (elixir) lib/kernel/parallel_compiler.ex:114: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

Put the code in e.ex and compile with elixirc e.ex. There are also some blank lines in the output (and in the file), but I can't get them to appear on here; S.O. eats them.

\$\endgroup\$
0
\$\begingroup\$

F#

e.fs(1,11): error FS0010: Unexpected symbol ':' in implementation file

Compile with fsc --nologo e.fs. Again, there's an extra blank line I can't properly reproduce here. (Without the --nologo flag the compiler wants to announce itself and its version number and display a Microsoft copyright message.)

\$\endgroup\$
0
\$\begingroup\$

Syms, 202 bytes

Traceback (most recent call last):
  File "/opt/syms/syms.py", line 196, in <module>
    stack.append(("{"+str(stack.pop())+"}").replace("\\","\\\\").replace("&","\\&"))
IndexError: pop from empty list

Try it online! Works on TIO. May not work on your configuration.

\$\endgroup\$
0
\$\begingroup\$

KSH script, 48 bytes

Save as a file named k.

k[1]: not: not found [No such file or directory]

Try it online! Note that TIO saves KSH scripts as .code.tio, so it's a bit longer but still the same thing.

\$\endgroup\$
0
\$\begingroup\$

k, oK

Might as well group these answers together, since it's supposedly the same language. I must say, this general approach is quite versatile.

oK

Every error seems to have a lot of environment-specific information, because, well, JavaScript is behind it all. Try it online!

/opt/ok/oK.js:876
    throw new Error("unexpected character '"+text[0]+"'");
    ^

Error: unexpected character ')'
    at Object.parse (/opt/ok/oK.js:876:8)
    at Object.<anonymous> (/opt/ok/repl.js:62:43)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:390:7)
    at startup (bootstrap_node.js:150:9)

k

Notice the space at the bottom. This works in 2016.06.28 (c) arthur whitney version of kmac.

a
^
value error
 

Example of it working.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.