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

96 Answers 96

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

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

Pepe, 9 bytes

RRRERROR!

Link to interpreter (paste the code above, permalink removes the ! and O)

Explanation:

Like I explained here, the interpreter ignores characters other than R,r,E,e so the code is:

RRRERRR

Now to explain:

  RE    # Push 0
RR      # (RR flag: doesn't exist)
    RRR # There is no command RRR, so output RRRERROR!
\$\endgroup\$
  • \$\begingroup\$ I like the enthusiasm of this error message. \$\endgroup\$ – Ørjan Johansen Jan 20 at 8:19
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\$
  • \$\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\$ – val Jul 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\$
4
\$\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\$
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\$

Malbolge, 32 bytes

invalid character in source file

Try it online!

\$\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\$
  • 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\$ – clap 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\$ – clap 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\$ – clap 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\$
  • 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\$

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

Python 3, 28 bytes

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

TI-83/84 Basic

Simple & for your calculator

ERR:SYNTAX
\$\endgroup\$
  • 12
    \$\begingroup\$ Doesn't work. Even if it did, it would be missing the 1:Quit\n2:Goto. \$\endgroup\$ – lirtosiast Sep 1 '15 at 1:44
2
\$\begingroup\$

Factor

No word named "No" found in current vocabulary search path

Guess what it prints?

No word named "No" found in current vocabulary search path
\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

MATLAB, 66 bytes

Undefined function 'Undefined' for input arguments of type 'char'.

This outputs the same to STDERR (shown in the console in red):

enter image description here

This is actually pretty unknown functionality (and it's rarely useful), which is why the MATLAB submission in the "Hello World!"-challenge may be improved.

This works because MATLAB will automatically interpret a command on the form <word_1 word_2 word_3 word_4>, with no surrounding brackets, as a function on the form:

word_1('word_2')`

That is, it calls a function word_1 and gives the single input argument after the first, and in front of the second space as a string input to that function.

"Real life"-examples that can be used for golfing:

disp Hello   % Shorter than disp('Hello')
Hello

disp Hello World!
Hello

nnz variable
ans =
     8

Note that it will always interpret it as a string, it will not evaluate it:

variable = 3;
nnz variable
ans =
     8
nnz(variable)
ans =
     1
\$\endgroup\$
  • \$\begingroup\$ In my current MATLAB version (R2016b), this can be considerably shortened to 43 bytes: Undefined function or variable 'Undefined'.. \$\endgroup\$ – Sanchises Jun 13 '17 at 9:20
  • \$\begingroup\$ Really, it doesn't treat the words after Undefined as string inputs? What happens if you do Undefined('function','or','variable')? In previous versions these commands are equivalent. It doesn't tell you that the character input is invalid? It makes sense, but it's definitely new behavior. What about a=2;b={};a(b). Or just a({1}) without initializing anything first? \$\endgroup\$ – Stewie Griffin Jun 13 '17 at 9:26
  • \$\begingroup\$ It does, hence "function or variable". However, I think the old error message was misleading, because 'Undefined' does not have to be a function, but could indeed be a variable, and many (most) functions are defined for arbitrary input, seeing as there is no native way that I know of to define a function like y=f(uint32 x), so saying that a function is not defined for 'char' does not make sense. \$\endgroup\$ – Sanchises Jun 13 '17 at 9:36
  • \$\begingroup\$ As for your examples: Undefined('function','or','variable') returns Undefined function or variable 'Undefined'. (indeed, you could be indexing into the variable Undefined); the latter two examples give Function 'subsindex' is not defined for values of class 'cell'. \$\endgroup\$ – Sanchises Jun 13 '17 at 9:38
  • \$\begingroup\$ I agree, the new behavior makes more sense than the old one... I'm just surprised that they changed it. It makes this slightly outdated. \$\endgroup\$ – Stewie Griffin Jun 13 '17 at 10:01
2
\$\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\$
  • \$\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
2
\$\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\$
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\$

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.