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

95 Answers 95

1
\$\begingroup\$

Cobra

test.cobra(1): error: Expecting use, assembly, namespace, class, interface or enum, but got "test".
Compilation failed - 1 error, 0 warnings
Not running due to errors above.
\$\endgroup\$
1
\$\begingroup\$

Befunge on Wasabi v1.4

There is an interpreter for Befunge called Wasabi, and when an error appears the error message is in the format of a dialog box. This is the program:

Unsupported Command : 'U' at (1, 0). Ignore next syntax error(s)?

To test, download Wasabi v1.4 and insert the above program.

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

C++

(Using Apple LLVM in Xcode)

Unknown type name 'Unknown'
Expected ';' after top level declarator
\$\endgroup\$
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.

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

CJam

Syntax error:
java.lang.RuntimeException: y not handled
\$\endgroup\$
1
\$\begingroup\$

Loader (using the official Java interpreter):

This language is newer than the challenge, so it may not be eligible to compete (I'm not sure whether or not that rule applies for popularity contests, actually...)

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

JavaScript

Uncaught SyntaxError: Unexpected identifier

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

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

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

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

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

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

ESOPUNK (Non-competing)

Language postdates the challenge.

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

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

ZSH (macOS), 20 bytes excluding newline

 zsh: bad pattern: ^[
\$\endgroup\$
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\$

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.

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

CJam, 12 bytes

u not handled

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

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

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

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

Go

Try it with this embedded repl.it page:

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

\$\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, privacy policy and cookie policy

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