113
\$\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 '14 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 '15 at 12:57
  • 2
    \$\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 '17 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 '17 at 21:50
  • 1
    \$\begingroup\$ @SteveBennett Why haven't you made that challenge yet? \$\endgroup\$ May 28 '17 at 1:53

111 Answers 111

1 2 3
4
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\$

Swift

This is a bit of a stretch. Bear with me.

The source MUST be encoded as UTF-16. Formatting the following as UTF-16:

swift.swift:1:1: error: input files must be encoded as UTF-8 instead of UTF-16
??^@s^@w^@i^@f^@t^@.^@s^@w^@i^@f^@t^@:^@1^@:^@1^@:^@ ^@e^@r^@r^@o^@r^@:^@^@i^@n^@p^@u^@t^@ ^@f^@i^@l^@e^@s^@ ^@m^@u^@s^@t^@ ^@b^@e^@\^@e^@n^@c^@o^@d^@e^@d^@ ^@a^@s^@ ^@U^@T^@F^@-^@8^@ ^@i^@n^@s^@t^@e^@a^@d^@ ^@o^@f^@ ^@U^@T^@F^@-^@1^@6^@

where ^@ is emacs-speak for an embedded NUL and the ? characters are genuine ASCII question marks. Outputting to console (cat doesn't work, being ignorant of UTF16):

$ iconv -f utf-16 swift.swift

swift.swift:1:1: error: input files must be encoded as UTF-8 instead of UTF-16
??swift.swift:1:1: error: input files must be encoded as UTF-8 instead of UTF-16

and compiling:

$ swiftc swift.swift

We get:

swift.swift:1:1: error: input files must be encoded as UTF-8 instead of UTF-16
??swift.swift:1:1: error: input files must be encoded as UTF-8 instead of UTF-16

As desired.

CAVEATS:

  • The terminal is taking the 16-bit header BOM \xFF\xFE in the error message from swiftc and degrading it as ASCII ?? in the console.
  • When the swift compiler is run in an Emacs shell, the terminal settings do not process the unprintable ASCII characters, instead rendering them in Octal.
  • When the source is rendered in an Emacs buffer, which is UTF-16 aware, the first line appears correctly, and the ?? appears correctly, and but the remaining characters are shown interspersed with NUL literals rendered as ^@.
  • cat in the Terminal doesn't work either, being unaware of UTF-16.
  • A UTF16-aware output utility is needed: iconv -f utf-16 swift.swift, where the terminal emulator subsequently discards the interspersed NUL characters on the second line.
  • In MacOS, swiftc leverages terminal capabilities to produce bold and color escape codes. To avoid this ambiguity, you can use export TERM=dumb.

I'm claiming it's a quine as long as the source is rendered with a UTF-16 aware output utility and a terminal that discards ANSI formatting, NULs, and degrades unprintable characters to ?.

USING TextEdit

You can also make a more visually convincing argument using ˛ˇ in place of ?? where you keep the input as UTF-16 and let Swift output the (invalid) UTF-8 output with swiftc swift.swift > out 2>&1 and open out in TextEdit. Side by side, the input and output indeed are rendered identically. No less dubious under the covers, but looks a lot less dubious.

So...when you say exactly identical, what exactly do you mean?

If the output must be re-usable as the input, the quine constraint is indeed violated. And if you argue it's OK to cycle the UTF8 compiler output back to UTF16 source, that seems promising, but doesn't work because the output of swiftc is neither valid UTF-8 nor UTF-16: it is not valid to embed the BOM header midstream in either encoding. It's just terminal poo. Having fun yet?

It's an interesting foray into encoding and terminals, at the least!

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

Grok, 20 bytes

You don't grok Grok.

Try it Online!

Grok has only one error message, and one of the ways to trigger it is to try to execute an invalid command. In this case, oun'tgrG. are all invalid commands, so when the execution reaches the first o, it errors out, printing the source code.

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

CJam, 12 bytes

u not handled

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

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

Straw

/opt/straw/straw.rb:108:in `initialize': no implicit conversion of nil into String (TypeError)
    from /opt/straw/straw.rb:108:in `new'
    from /opt/straw/straw.rb:108:in `step'
    from /opt/straw/straw.rb:225:in `run'
    from /opt/straw/straw.rb:254:in `<main>'

Try It Online!

\$\endgroup\$
2
  • \$\begingroup\$ Works only if path to interpreter is /opt/straw/straw.rb. (Not that this answer is bad, just to let you know.) \$\endgroup\$
    – user48538
    Sep 15 '16 at 14:51
  • \$\begingroup\$ Oh, and also, Try it online! also outputs the timings for the program run and the exit code. \$\endgroup\$
    – user48538
    Sep 15 '16 at 14:51
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\$
0
\$\begingroup\$

Python 3

  File ".py", line 1
    File ".py", line 1
    ^
IndentationError: unexpected indent
\$\endgroup\$
1
  • \$\begingroup\$ The file must be named ".py" for this to work. \$\endgroup\$
    – aaay aaay
    Dec 1 '17 at 19:39
0
\$\begingroup\$

ink, 65 bytes

ERROR: 'q' line 1: Empty diverts (->) are only valid on choices

Try it online!

Must be saved in a file called q, which is why the code on TIO is 7 bytes longer.

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

Snowman, 121 bytes

SnowmanException thrown at tokenize
  what():  at tokenize: letter operator terminated prematurely?
fatal error, aborting

Try it online!

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

33

Very simple. : isn't a valid command, so it's easy to make an unrecognised token error quine. The error is just where the : is in the code.

33 (1:8): Unrecognised token
\$\endgroup\$
0
\$\begingroup\$

GNU Smalltalk REPL

REPL is always acceptable, and I only learned the Smalltalk REPL and don't know how to save programs in a file. (I think TIO does not have Smalltalk yet.)

stdin:1: expected expression

This will work when you start the REPL for the first time.

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

Red 0.6.3

*** Error: not a Red program!

Newline included. Save as a .red file and run with red <filename>.red.

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

Pxem (pxemi.2.min.posixism), Filename: 14 bytes + Content: 0 bytes = 14 bytes.

  • Filename (has trailing LF!): .a B4 .[wxyz]
  • Content: empty.

Try it online!

\$\endgroup\$
0
\$\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\$
0
\$\begingroup\$

PPL, 79 bytes

Reference error on line 3, column 3

  a()
  ^

The identifier a is not defined

I haven't implemented syntax checking properly, so only reference errors and type errors are thrown (plus syntax checking in rare cases). Pretty simple answer, frankly. Attempts to call the nonexisting a function (just a without the call does not work because my interpreter does not check for invalid expressions in some cases) I know my language is not very good but I'm too lazy to work on it.

\$\endgroup\$
1 2 3
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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