Fake error message

18

1

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.

Ming-Tang

Posted 2011-04-26T23:21:03.147

Reputation: 5 383

A solution can be the [tag:popularity-contest]. Well, an objective winning criteria. – Johannes Kuhn – 2013-07-07T09:09:07.547

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.

– dmckee --- ex-moderator kitten – 2011-04-27T02:03:05.303

http://meta.codegolf.stackexchange.com/q/305/78 – dmckee --- ex-moderator kitten – 2011-04-27T02:25:49.963

Answers

35

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.

Keith Randall

Posted 2011-04-26T23:21:03.147

Reputation: 19 865

This is brilliant – Cruncher – 2013-12-13T15:59:24.190

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 – The Matt – 2018-07-09T00:50:14.653

10

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
$ 

Florian F

Posted 2011-04-26T23:21:03.147

Reputation: 591

9

BrainF***

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

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

Ry-

Posted 2011-04-26T23:21:03.147

Reputation: 5 283

1It's nice to see you on CG, Minitech :) – Bojangles – 2013-07-07T07:40:35.507

Lol, revision history is amusing :P – Doorknob – 2013-08-17T02:06:51.613

5For those of you without BF compilers who are curious, this prints, "F***! Syntax error: closing ] token appeared before an opening [ token" – Peter Olson – 2011-04-28T01:38:08.243

1

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)

Nate Koppenhaver

Posted 2011-04-26T23:21:03.147

Reputation: 380

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 ;) – Nate Koppenhaver – 2011-04-27T18:16:54.947

0

Game Maker Language

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

Timtech

Posted 2011-04-26T23:21:03.147

Reputation: 12 038

0

ACTIONSCRIPT 3

trace("TypeError: Error #1009: Cannot access a property or method of a null object reference.");

wuiyang

Posted 2011-04-26T23:21:03.147

Reputation: 371