# 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? – Peter Taylor 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 – SuperJedi224 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. – Steve Bennett 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? – Adám May 7 '17 at 21:50
• @SteveBennett Why haven't you made that challenge yet? – CalculatorFeline May 28 '17 at 1:53

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

# CJam

Syntax error:
java.lang.RuntimeException: y not handled


# JavaScript

Uncaught SyntaxError: Unexpected identifier


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

• 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? – wizzwizz4 Oct 8 '16 at 12:57
• It generates "SyntaxError: missing ; before statement" in Firefox. – 12Me21 Jan 25 '17 at 13:24

# Codelike, 36 Bytes

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


Try it!

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.

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


# 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


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

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

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

# Recursiva, 7 bytes

Error!



Try it online!

# 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]$


# 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

# K (ngn/k), 2 bytes

'c


Try it online!

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

• 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 – Thaufeki Oct 11 '18 at 17:29

# MiLambda

ERROR_NOHALT


Try it online!

Seems like a short solution

# ZSH (macOS), 20 bytes excluding newline

 zsh: bad pattern: ^[

• all error messages should include this: : ^[ – roblogic Aug 23 at 5:06

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

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

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

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)


# ESOPUNK, 38 bytes

Invalid instruction INVALID at line 0.

• Wasn't this posted after the postdated language consensus was changed? – ASCII-only Jan 20 at 6:15
• No idea, to be honest. I'm not exactly in the race for anything, though, so I'm not particularly worried. – SIGSTACKFAULT Jan 24 at 23:37

# CJam, 12 bytes

u not handled


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

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

• Works only if path to interpreter is /opt/straw/straw.rb. (Not that this answer is bad, just to let you know.) – user48538 Sep 15 '16 at 14:51
• Oh, and also, Try it online! also outputs the timings for the program run and the exit code. – user48538 Sep 15 '16 at 14:51

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

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

## Go

Try it with this embedded repl.it page:

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

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

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

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


Python 3

  File ".py", line 1
File ".py", line 1
^
IndentationError: unexpected indent

• The file must be named ".py" for this to work. – aaay aaay Dec 1 '17 at 19:39

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

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

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