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

103 Answers 103

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

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

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

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

Python 3

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

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

Snowman, 121 bytes

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

Try it online!

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

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

Turing Machine Code, 70 bytes

Syntax error on line 1: <current symbol> should be a single character!

Try it online!

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

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

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

Rust v1.45.2 (via Rust Playground)

Code (1126 bytes):

error: unknown start of token: `
 --> src/lib.rs:1:32
  |
1 | error: unknown start of token: `
  |                                ^
  |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
  |
1 | error: unknown start of token: '
  |                                ^

error: unknown start of token: `
 --> src/lib.rs:4:36
  |
4 | 1 | error: unknown start of token: `
  |                                    ^
  |
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
  |
4 | 1 | error: unknown start of token: '
  |                                    ^

error: character constant must be escaped: '
 --> src/lib.rs:7:56
  |
7 | help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
  |                                                        ^

error: unterminated character literal
 --> src/lib.rs:9:36
  |
9 | 1 | error: unknown start of token: '
  |                                    ^

error: aborting due to 4 previous errors

error: could not compile `playground`.

Try it online (error message might differ in future versions of the language, though)

Compile errors in Rust all start with "error:", so copy/pasting the errors into the source a bunch of times eventually leads to these error messages. Default settings for the Rust Playground were used. That means 2018 edition, stable branch, and debug mode. I don't know what the target triple is.

| improve this answer | |
\$\endgroup\$
-2
\$\begingroup\$

><>, 25 bytes

something smells fishy...

Try it online!

Explanation

The only error in ><> is something smells fishy....

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