18
\$\begingroup\$

Write a program that prints out the syntax error message of the compiler or interpreter. The error message should be misleading so that code maintainers will take days to find out that the error was faked, that means, you should obfuscate (and hide your intention). Also, the error must be as exact as possible, and should reference to the code correctly.

For complied languages, assume your code maintainer will do compile program.p && ./program on the command line to compile AND run the program, that means, he cannot distinguish if the output comes from the compiler or the program itself. Also, assume your code maintainer will turn on syntax error messages.

For reference, here is an example I made: https://gist.github.com/359604

The DATA section encodes the string of error message, and the hash %abcdef is the decode table. The error printed references to the backslashes, which makes a code maintainer will try to count the backslashes.

Entries will be graded by:

  • Code has an deceptively obvious intention /6
  • Code reproduces error correctly /16 (your point starts with 16, and divide by the corresponding factors for each inaccuracies)
    • Correct capitalization: 4
    • Correct line number and column number: 4
    • Correct wording: 2 for each incorrect words
  • The line number referenced misleads the code maintainer /3

For example,

./pythontest1.py: line 7: syntax error near token `('
./pythontest1.py: line 7: `   x=input("Enter a number:") #Number input'

gets 8 (16 / 2) on correctness for missing "unexpected" before "token", a normal Python interpreter displays

./pythontest1.py: line 7: syntax error near unexpected token `('
./pythontest1.py: line 7: `   x=input("Enter a number:") #Number input'

If your "code reproduces error correctly" point is under 1, your entry disqualifies.

In case of a tie, I will put up additional grading factors.

\$\endgroup\$
  • \$\begingroup\$ Uh...I closed Sparky's recent obsfuscation question on account of not being objective, and now we've got Peter's underhanded thingy and this (which I admit makes a valiant effort to obtain objectivity). Rather than just sit on everything willy-nilly or chose based on my personal prejudice I'm going to open another topic on meta, or maybe resurrect an old one. Be aware that Jeff seems to think that "objective" is a requirement. \$\endgroup\$ – dmckee Apr 27 '11 at 2:03
  • \$\begingroup\$ meta.codegolf.stackexchange.com/q/305/78 \$\endgroup\$ – dmckee Apr 27 '11 at 2:25
  • \$\begingroup\$ A solution can be the popularity-contest. Well, an objective winning criteria. \$\endgroup\$ – Johannes Kuhn Jul 7 '13 at 9:09
35
+100
\$\begingroup\$

Python

import sys,traceback
try:
  f=open(sys.argv[0])
  print eval(f.readline())
except Exception, e:
  traceback.print_exc(0)

This is a program that should take a filename on the command line, evaluate the first line in it, and print the result. It has 2 bugs. The major bug is that it should use sys.argv[1], not sys.argv[0], so it ends up evaluating the program itself, not the contents of the file named by the first argument. The second bug is that the argument to print_exc makes it print only the deepest frame on the stack, hiding the fact that the error took place inside the eval. As a result, you get an error like this:

$ python fake_error.py twelve 
Traceback (most recent call last):
  File "<string>", line 1
     import sys,traceback
          ^
 SyntaxError: invalid syntax

This looks very much like the first line of the program has a syntax error. It's not quite right as the file is <string>, not fake_error.py, but otherwise it is indistinguishable from the case where, for example, you spell import wrong.

Both errors are somewhat "underhanded" in that they could be accidental.

\$\endgroup\$
  • \$\begingroup\$ This is brilliant \$\endgroup\$ – Cruncher Dec 13 '13 at 15:59
  • \$\begingroup\$ Brilliant. This reminds me of another oddity of Python. Running raise in Python 2, but in IDLE, python's default IDE, causes an internal error printing gibberish about queues. Traceback (most recent call last): ** IDLE Internal Exception: File "2.7/lib/python2.7/idlelib/run.py", line 325, in runcode exec code in self.locals File "2.7/lib/python2.7/idlelib/run.py", line 111, in main seq, request = rpc.request_queue.get(block=True, timeout=0.05) File "2.7/lib/python2.7/Queue.py", line 176, in get raise Empty \$\endgroup\$ – The Matt Jul 9 '18 at 0:50
10
\$\begingroup\$

Reminds me a practical joke.

$ ls -l
$ cat readme.txt
cat: readme.txt: No such file or directory
$ echo 'cat: readme.txt: No such file or directory' >readme.txt
$ ls -l
total 8
-rw-r--r--  1 florian  staff  43 Mar 16 09:52 readme.txt
$ cat readme.txt
cat: readme.txt: No such file or directory
$ 
\$\endgroup\$
9
\$\begingroup\$

BrainF***

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>++++++++++[<+++++++++++<++++++++++<++++++++++<+++++++++++<+++++++++++<+++<+++++++++<+++<++++++++++<+++++++++++<++++++++++<+++++++++++<++++++++++<+++++++++++<+++++++++++<+++<+++++++++++<+++++++++<+++<++++++++++<+++++++++++<+++++++++++<++++++++++<++++++++++<+++++++++<+++<++++++++++<++++++++++<+++++++++++<+++++++++<++++++++++<+++++++++++<+++++++++++<+++++++++<+++<+++++++++++<++++++++++<++++++++++<+++++++++++<+++++++++++<+++<+++++++++<+++<++++++++++<+++++++++++<++++++++++<+++++++++++<+++++++++++<++++++++++<+++++++++<+++<+++++<+++++++++++<+++++++++++<+++++++++++<+++++++++++<++++++++++<+++<++++++++++++<+++++++++<+++++++++++<+++++++++++<++++++++++++<++++++++<+++<+++<++++<++++<++++<+++++++>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<.>++.>++.>++.>+++.>++.>+++.>+.>.>++++++.>+++++++.>.>++.>+.>++++.>++++.>+.>++++.>++++++++.>++.>+++++++++.>++++++++.>+.>+++++.>+++++.>.>+++.>++.>+++.>++.>++++++.>+.>+++++++.>+.>.>++.>+++++++.>++.>++.>+.>+++++++.>++++.>+.>.>++.>++++++++.>+.>++.>+.>++++.>+.>++.>+++++++.>.>++.>+.>++.>+.>.>+++++.>.>+++.>++.>+.>++.>++++++.>+.>+++++++.>+.>.>

I can't find the particular compiler I used before, but I assure you that that is the exact error message.

\$\endgroup\$
  • 5
    \$\begingroup\$ For those of you without BF compilers who are curious, this prints, "F***! Syntax error: closing ] token appeared before an opening [ token" \$\endgroup\$ – Peter Olson Apr 28 '11 at 1:38
  • 1
    \$\begingroup\$ It's nice to see you on CG, Minitech :) \$\endgroup\$ – Bojangles Jul 7 '13 at 7:40
  • \$\begingroup\$ Lol, revision history is amusing :P \$\endgroup\$ – Doorknob Aug 17 '13 at 2:06
1
\$\begingroup\$

Java

throw new Error();  

I didn't know if you meant actually throwing an unhandled exception (as in that example), or simulating an error message. If that is the case, this should work:

C

printf("FATAL ERROR #0xBAD\nProgram execution stopped\n\nIn line 123, character 321, of file 'buggy.c'");

(this assumes that stdio.h is #included)

\$\endgroup\$
  • \$\begingroup\$ oops, just read your post in-depth about the obfuscation part. i would add an obfuscator to it, but i currently don't have access to any ides. [ :( ] when i get one, i will definetly post an obfuscated version (who knows, maybe in even another lang ;) \$\endgroup\$ – Nate Koppenhaver Apr 27 '11 at 18:16
0
\$\begingroup\$

Game Maker Language

show_error("Error: Undefined variable a##Line 1, character 4, of event Create in obj_controller",0)
\$\endgroup\$
0
\$\begingroup\$

ACTIONSCRIPT 3

trace("TypeError: Error #1009: Cannot access a property or method of a null object reference.");
\$\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.