117
\$\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 '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\$ 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\$ 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\$ May 28 '17 at 1:53

112 Answers 112

5
\$\begingroup\$

Forth

Try it here

This was surprisingly easy to come up with.

a : error(-13): word not found
\$\endgroup\$
0
5
\$\begingroup\$

zsh (Linux)

zsh: command not found: zsh:

Should work with some small changes in just about any other shell.

\$\endgroup\$
5
\$\begingroup\$

Bash

$ bash: bash:: command not found
bash: bash:: command not found
\$\endgroup\$
5
\$\begingroup\$

ArnoldC, 28 bytes

WHAT THE FUCK DID I DO WRONG

This is the only error message in ArnoldC, though you do have to turn off stack traces.

\$\endgroup\$
5
\$\begingroup\$

GNU Make 4.1

make: *** No rule to make target 'No', needed by 'make'.  Stop.

This is syntactically valid:

  • Make tries to evaluate the target named make (first target is the default),
  • which depends on the target named No,
  • which it has no rule for.
\$\endgroup\$
5
  • 1
    \$\begingroup\$ But don't ***, 'No', and Stop. contain syntactically invalid tokens? Also, have you noticed that your profile shows a picture of someone rushing but your name is eush77? \$\endgroup\$
    – MD XF
    Jun 7 '17 at 21:30
  • 1
    \$\begingroup\$ @MDXF Oh, no. *** is a wildcard, 'No' is quoted, and the dot in Stop. is allowed (as in filenames, e.g. Stop.c). You can run make --debug to see for yourself that it proceeds exactly as I described. You can also touch No to see the message change :) \$\endgroup\$
    – eush77
    Jun 7 '17 at 22:42
  • \$\begingroup\$ @MDXF I'm sorry, I didn't get the joke about rushing and the first letter of my name. Is it somehow unusual on this site? \$\endgroup\$
    – eush77
    Jun 7 '17 at 22:48
  • \$\begingroup\$ Ah, okay. +1 and I didn't mean for it to be a joke; I thought you may have had a typo in your username. My bad. \$\endgroup\$
    – MD XF
    Jun 7 '17 at 22:59
  • 3
    \$\begingroup\$ @MDXF I never thought about my username this way! No, its origin is totally unrelated to the pic :-) \$\endgroup\$
    – eush77
    Jun 7 '17 at 23:25
5
\$\begingroup\$

x86 assembly

Bytecode:

53 65 67 6d 65 6e 74 61 75 69 6f 6e 20 66 61 75
6c 74 20 28 63 6f 72 65 20 64 75 6d 70 65 64 29

i.e. the text

Segmentation fault (core dumped)

Crashes immediately because the second instruction (the first being just "push %[er]bx") is

insl (%dx), %gs:(%di)

which fails because (a) ins cannot take segment overrides, (b) %dx and %di are almost certainly uninitialized, (c) %di is a 16-bit memory address and therefore can't be accessed in long mode, (d) ins is an invalid instruction outside of real mode.

The exact output may vary depending on what system this is run on, but it is likely that it will contain some form of illegal instruction.

\$\endgroup\$
5
\$\begingroup\$

Malbolge, 32 bytes

invalid character in source file

Try it online!

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

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Glad someone else thought of Piet. I really want to make my own image-based esolang some day. \$\endgroup\$
    – Domino
    Jan 28 at 15:59
4
\$\begingroup\$

Lua

Code:

lua: ERROR.lua:1: function arguments expected near '.'

It seems fairly easy to do with lua. I also modified it to work on ideone.com as:

luac: prog.lua:1: function arguments expected near '.'

Try it.

\$\endgroup\$
1
  • \$\begingroup\$ Yeah, got it in few iterations starting from single local. Won't you mind if I'll explain this in answer's body? \$\endgroup\$ Jul 19 '19 at 17:51
4
\$\begingroup\$

Rebol

Interestingly, the error message here parses as symbols/tokens:

x
** Script error: x has no value
** Where: do either either either -apply-
** Near: do intern code

So despite looking error-like, it could be made a valid Rebol program if you gave all the words meanings.

However if you wanted an error at the parse phase vs. a runtime error in the code, the program/error could be:

1A
** Syntax error: invalid "integer" -- "1A"
** Where: to case load either either -apply-
** Near: (line 1) 1A

So given that distinction is possible, you can do fun things if you redefine ** from exponentiation into something else (which I can't think of how to make useful for this particular challenge, given it's a quine.)

(Note: Trying to abuse it for a trick uncovered a peculiarity of what happens when ** (an infix operator) is redefined and then used immediately after. I tried:

**: function [:a :b :c :d :e :f] []
** Syntax error: invalid "integer" -- "1A"
** Where: to case load either either -apply-
** Near: (line 1) 1A

My goal was to override the ** so that it would accept its arguments unevaluated. That way ** Syntax error: invalid "integer" -- "1A" (or whatever) would not attempt to assign invalid to error, but pass the symbols to **. But because ** is infix it attempted to raise the function body to the power of Syntax prior to the completion of the assignment of **:.

It can be remedied by putting any token between the [] and the **. But it helps to remember how your language evaluator works. :-P)

\$\endgroup\$
4
\$\begingroup\$

R (GUI)

Error: unexpected symbol in "Error: unexpected symbol"

The issue here is replicating the ", which causes the error message to change from unexpected symbol to unexpected string constant. Pretty much any error R throws will have the form Error: <something> in "<bad code>", so you will pretty much always have to contend with the quoting. I tried this several other ways and always ended up falling back here.

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

Pyth

    s_push: parser stack overflow
Traceback (most recent call last):
  File "pyth.py", line 752, in <module>
    exec(code_to_remove_tools + py_code_line, environment)
MemoryError

Try it online!

\$\endgroup\$
4
\$\begingroup\$

Python 3, 28 bytes

SyntaxError: invalid syntax
\$\endgroup\$
4
\$\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\$
4
\$\begingroup\$

m4 (before 1.4.18-3 Termux patch), Termux, Android 11, 35 bytes

Who said the error had to be caused directly?

FORTIFY: %n not allowed on Android

Includes trailing newline.

m4 uses a very old version of Gnulib.

Since Android doesn't support %n in printf, Gnulib will replace every printf function in libc with its own custom implementation.

However, stupidly, said function will still use libc's snprintf function internally (which it is supposedly trying to replace because it doesn't work 🤔), and when using it, it attempts to use %n every single time it is called, even if %n isn't in the original format string.

%n used to be silently ignored on Android (similar to macOS), but Android 11 made these errors fatal, causing this error to be printed followed by abort().

I used set +m to prevent Bash from printing the signal error, and I had to compile from source to undo the -3 patch.

The file itself doesn't matter: m4 is guaranteed to crash no matter what. This includes running with no arguments.

See this Github issue

enter image description here

\$\endgroup\$
3
\$\begingroup\$

Go

Another fairly easy one using the "general approach" provided in the other answer. I still like my JavaScript ones better.

can't load package: package : 
prog.go:1:1: expected 'package', found 'IDENT' can
prog.go:2:2: invalid package name _

Try it.

\$\endgroup\$
3
\$\begingroup\$

Lua (console), 35 bytes

This is what you get in the Lua console with the usual iterative approach:

stdin:1: '<name>' expected near '1'

which is a bit shorter than the one obtained for putting the code in a file.

\$\endgroup\$
3
\$\begingroup\$

ksh

$ ksh: ksh::  not found.
ksh: ksh::  not found.
\$\endgroup\$
7
  • 4
    \$\begingroup\$ Also works with bash: bash: bash:: comand not found \$\endgroup\$
    – Shelvacu
    Aug 20 '14 at 0:54
  • \$\begingroup\$ @shelvacu on my build of bash, bash: command not found errors with bash:: command not found, which errors with bash::: command not found. Am I doing something wrong? \$\endgroup\$
    – clapp
    Nov 2 '15 at 15:25
  • \$\begingroup\$ @ConfusedMr_C must be a case of different versions. I am running 4.3.042-3 on x64 Arch Linux, and it works. \$\endgroup\$
    – Shelvacu
    Nov 3 '15 at 5:42
  • \$\begingroup\$ @shelvacu I'm running x64 Ubuntu, with whatever version of bash came with Ubuntu 14.04.3. Also, you can do zsh: command not found: zsh: in zsh. \$\endgroup\$
    – clapp
    Nov 3 '15 at 23:41
  • \$\begingroup\$ @shelvacu Sorry, I just found out, I'm using 4.3.11(1)-release on x64 Ubuntu 14.04.3. \$\endgroup\$
    – clapp
    Nov 6 '15 at 7:21
3
\$\begingroup\$

Perl

syntax error at quine.pl line 2, at EOF
Execution of quine.pl aborted due to compilation errors.

Replace quine.pl with whatever you named the file and enjoy.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Is it even possible to have a syntax error in perl? From what I've read online (mainly here) it seems as though perl accepts anything? \$\endgroup\$
    – user63571
    Jan 28 '17 at 0:27
3
\$\begingroup\$

Java, in Eclipse

Syntax error on tokens, delete these tokens
\$\endgroup\$
3
\$\begingroup\$

Processing IDE

Probably the friendliest error message I've ever seen.

Syntax error, maybe a missing semicolon?

Result

doodoood

Technically this is cheating a bit because the pane below it prints expected SEMI, found 'error'. Unfortunately the word error is written in single quotes, so trying to copy that into the source of the program causes it to spit out a massive "Badly formed character constant" error... which does not include any singly-quoted words allowing for it to quine itself.

\$\endgroup\$
3
\$\begingroup\$

SmileBASIC

NEXT without FOR in 0:1

Whenever the pre-run parser encounters a NEXT which isn't paired with a FOR, it produces the error NEXT without FOR in slot:line. Here, the code is in slot 0 and on line 1.

\$\endgroup\$
2
  • \$\begingroup\$ Syntax error in 0:1 is shorter \$\endgroup\$
    – 12Me21
    Jan 24 '17 at 6:41
  • 2
    \$\begingroup\$ I had that first, but this is a popularity-contest, so I went with something more creative. \$\endgroup\$
    – snail_
    Jan 24 '17 at 12:08
3
\$\begingroup\$

(t)csh

Unmatched '.

The trailing newline is needed to produce an exact match. Run it with csh quine.csh (or just type it into the shell, that works too).

\$\endgroup\$
3
\$\begingroup\$

Cubically, 94 bytes


Notepad: 0

   000
   000
   000
111222333444
111222333444
111222333444
   555
   555
   555

There are newlines at the start and end. (Cubically automatically dumps its memory to STDERR when the program finishes.)

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Technically this isn't an error. so it does not "generate at least one error message" \$\endgroup\$
    – ASCII-only
    Jun 13 '18 at 13:26
  • 1
    \$\begingroup\$ This seems to be an error message as far as I can tell. It does output to STDERR afterall. \$\endgroup\$
    – Grain Ghost
    Dec 16 '20 at 23:15
3
\$\begingroup\$

Javascript (Chrome/V8), 65 41 39 Bytes

Uncaught =u=_=>{throw`=u=${u};u()`};u()

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Rust, 323 166 164 bytes

Call your program a. and use rustc a..

error: unknown start of token: \
 --> a.:1:32
  |
1 | error: unknown start of token: \
  |                                ^

error: aborting due to previous error
\$\endgroup\$
3
\$\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!

\$\endgroup\$
3
\$\begingroup\$

A Pear Tree

a partridge

Try it online!

Almost every program (that isn't very long) prints a partridge in A Pear Tree.

One of the goals of the language was to be good at challenges; as such, it tries to find a substring of the program that has a very specific property that rarely occurs by chance, and starts running the program there. If it can't find an appropriate entry point, it prints an error. The actual text of the error message was chosen for the The Twelve Days of Christmas reference. (Actually, the design for the language worked the other way round; the main goal was to have a language which errored out on almost any source code, so that it would make the reference in question, so I set about trying to work out what sort of language design would naturally end up doing that.)

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

\$\endgroup\$
3
\$\begingroup\$

Setanta, 97 bytes

Eisceacht ar líne 1: Suíomh 19: Ag súil le uimhir, téacs, bool, athróg, liosta, nó gníomh.

Try it here!

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