125
\$\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, 2014 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, 2015 at 12:57
  • 3
    \$\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, 2017 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, 2017 at 21:50
  • 1
    \$\begingroup\$ @SteveBennett Why haven't you made that challenge yet? \$\endgroup\$ May 28, 2017 at 1:53

131 Answers 131

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

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

Snap! (scratchblocks syntax)

Hmm...
a custom block definition is missing
\$\endgroup\$
0
\$\begingroup\$

JavaScript

Thought I would make an updated JS answer.

Firefox:

Uncaught SyntaxError: unexpected token: identifier
Google Chrome:
Uncaught SyntaxError: Unexpected identifier 'SyntaxError'

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

Perl 5, 99 bytes code + 8 bytes file path, 107 bytes

File must be named >>;/\1/a to close off the <-- HERE ... <-- HERE and to reference the nonexistent group in a regex.

Link is to a Bash test suite.

Reference to nonexistent group in regex; marked by <-- HERE in m/\1 <-- HERE / at >>;/\1/a line 1.

Try it online!

\$\endgroup\$
1 2 3 4
5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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