107
\$\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
    \$\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\$ – Peter Taylor 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\$ – SuperJedi224 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\$ – Steve Bennett 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\$ – CalculatorFeline May 28 '17 at 1:53

102 Answers 102

1
\$\begingroup\$

ChucK

Here's my contribution:

[chuck]:line(1).char(8): syntax error

This works if you first type it into the editor, save it as "chuck", and then run it once. If you run it another time the number in char() goes up by eight.

ChucK can be downloaded here.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

CJam

Syntax error:
java.lang.RuntimeException: y not handled
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript

Uncaught SyntaxError: Unexpected identifier

Throws a generic Unexpected identifier error (in Chrome, at least) because it doesn't recognize Uncaught as an identifier.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I presume that the exact text this generates is not in the standard. Could you please include the browser / JavaScript engine that this submission is "programmed" in? \$\endgroup\$ – wizzwizz4 Oct 8 '16 at 12:57
  • \$\begingroup\$ It generates "SyntaxError: missing ; before statement" in Firefox. \$\endgroup\$ – 12Me21 Jan 25 '17 at 13:24
1
\$\begingroup\$

Codelike, 36 Bytes

Error at (1,1): Unknown character: E

Try it!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Ada

test.adb:1:01: compilation unit expected

Really just make an ada file, toss it at the start as above and compile with gcc filename.adb -c.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

ForceLang

Works in the latest version of the reference implementation as of the time this answer was written.

Exception in thread "main" lang.exceptions.IllegalInvocationException: Exception is not a function.
    at lang.ForceLang.parse(ForceLang.java:52)
    at lang.ForceLang.main(ForceLang.java:129)
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Python 3.5

Note: the source file should be named "1" for this to work

  File "1", line 1
    File "1", line 1
    ^
IndentationError: unexpected indent
| improve this answer | |
\$\endgroup\$
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...

| improve this answer | |
\$\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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Recursiva, 7 bytes

Error!

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

NASM for x86: 45 bytes

e.asm:1: error: parser: instruction expected

Assemble (or attempt to assemble) with nasm e.asm

Just in case:

0:beau@beau-Latitude-E6330:[~/asm/q]$ nasm -v
NASM version 2.12.02 compiled on Feb  5 2017
0:beau@beau-Latitude-E6330:[~/asm/q]$ 
| improve this answer | |
\$\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

| improve this answer | |
\$\endgroup\$
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

| improve this answer | |
\$\endgroup\$
  • \$\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 '18 at 17:29
1
\$\begingroup\$

MiLambda

ERROR_NOHALT

Try it online!

Seems like a short solution

| improve this answer | |
\$\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!

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

ZSH (macOS), 20 bytes excluding newline

 zsh: bad pattern: ^[
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ all error messages should include this: : ^[ \$\endgroup\$ – roblogic Aug 23 '19 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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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.

| improve this answer | |
\$\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).

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

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!

| improve this answer | |
\$\endgroup\$
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)
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

ESOPUNK, 38 bytes

Invalid instruction INVALID at line 0.
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Wasn't this posted after the postdated language consensus was changed? \$\endgroup\$ – ASCII-only Jan 20 '19 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\$ – SIGSTACKFAULT Jan 24 '19 at 23:37
1
\$\begingroup\$

C (tcc), 42 bytes

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

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

MS SQL (Server version 2012), 64 bytes

Msg 2812, Level 16, State 62, Line 1
Incorrect syntax near '16'.
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

CJam, 12 bytes

u not handled

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

| improve this answer | |
\$\endgroup\$
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!

| improve this answer | |
\$\endgroup\$
  • \$\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.

| improve this answer | |
\$\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.)

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Go

Try it with this embedded repl.it page:

<script src="//repl.it/embed/Ew1N/0.js"></script>

| improve this answer | |
\$\endgroup\$

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.