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\$ Commented 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\$ Commented 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\$ Commented 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
    Commented May 7, 2017 at 21:50
  • 1
    \$\begingroup\$ @SteveBennett Why haven't you made that challenge yet? \$\endgroup\$ Commented May 28, 2017 at 1:53

134 Answers 134

1
\$\begingroup\$

GW-BASIC (least: 12 bytes)

Syntax error

Inspired by the Commodore 64 BASIC answer. Knocked off 2 bytes because IBM and DOS are better than Commodore :P You can download an emulator for GW-BASIC.

NEXT without FOR

Since GW-BASIC is a line-based language, it only evaluates the first instruction after a newline or colon :. Therefore, it reads NEXT and automatically fails it didn't read a FOR.

Apple ][ BASIC (13 bytes)

?SYNTAX ERROR

Woo, 1 less byte than the Commodore answer because the old Apples could beat a Commodore anyday :P

QBasic (43 bytes)

Parse failed: Syntax error at 1:1: Token(:)

Might be cheating because it only works on the first line.

Applesoft BASIC (69 bytes)

ParseError: Syntax error: Expected line number or separator in line 0

Also only works on the first line...

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

sed

By using this general approach, I have converged on several sed error quines. This may not work in your sed, in which case, you're using the wrong sed, and therefore would you please acquire necessary, error-quining sed.

Try it online! This version works in TIO, and probably not anywhere else. Open the "Debug" panel to see the error.

<code>sed: 1: test.sed: bad flag in substitute command: 'd'</code> and <code>gsed: file toast.sed line 1: extra characters after command</code>

Where sed is macOS's default sed, and gsed is a GNU sed.

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

Recursiva, 7 bytes

Error!

Try it online!

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

VB.Net, 32 Bytes

Create a new, empty project named 'A'. Set the startup object to "Sub Main" (it's a drop-down option). Create a new class called anything. Delete everything from the class and copy/paste the following:

'Sub Main' was not found in 'A'.

This works because a single quote is a comment, so it looks like a blank file :D

\$\endgroup\$
1
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
    Commented 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\$ Commented Mar 22, 2019 at 0:51
  • \$\begingroup\$ @ØrjanJohansen Oh, okay \$\endgroup\$
    – MilkyWay90
    Commented Mar 22, 2019 at 1:04
1
\$\begingroup\$

ZSH (macOS), 20 bytes excluding newline

 zsh: bad pattern: ^[
\$\endgroup\$
1
  • 2
    \$\begingroup\$ all error messages should include this: : ^[ \$\endgroup\$
    – roblogic
    Commented 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
    Commented Jun 18, 2019 at 2:56
  • \$\begingroup\$ @JoKing Yeah. It was even shortened on TIO because the name was too long \$\endgroup\$
    – MilkyWay90
    Commented 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
    Commented 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\$ Commented 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\$

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
    Commented 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\$ Commented 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
    Commented 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
    Commented 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
    Commented May 3, 2023 at 18:45
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\$
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\$

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.