Tips on developing Eclipse plugins – VI. – Automatic exception reporting to Bugzilla

Bugzilla is well known bug tracking software. I would like to show simple solution on how to implement automatic submitting of uncaught exceptions (caused or somehow connected with our code) to company Bugzilla system.

Server side

First thing we need is a small utility script called bugzilla-submit which can be found in BUGZILLA DIRECTORY/contrib/bugzilla-submit folder. It’s simple command line interface for submitting new bugs. This script reads .netrc file in the home directory (/var/www in our case) which must contain bugzilla system credentials:

machine "http://bugzilla.our-company.com"
login <an email address of bugzilla user>
password <password>

Second thing we need is to create a simple php script that will live on some publicly accessible server and will process POSTed bugs and submit them using the mentioned utility into bugzilla server (which may or may not be on the same machine). Basic skeleton of such script:
[php]
Some hard coded bug title“;

if (!isset($_POST[‘description’])) {
die(‘Error’);
}
$bug_descr=$_POST[‘description’];

$cmd = ‘export HOME=/var/www && ‘.
‘./contrib/bugzilla-submit/bugzilla-submit ‘.
‘-n -p “some hard coded product name” ‘.
‘-v “1.0” -c “General” -s ‘.escapeshellarg($bug_subj).’ ‘.
‘-d ‘.escapeshellarg($bug_descr).’ -r P3 -x “normal” ‘.
‘-H “PC” -o “Windows” “http://bugzilla.our-company.com”‘.
‘ 2>&1’;

exec($cmd, $out1);
$out2 = join( “
“, $out1 );
print($out2);
?>
[/php]

As you can see, the script is very simple as it allows only bug description to be modified (by our Eclipse plugin reporting system) and other fields are hard coded. It also isn’t secured in any way so anyone who knows URL of the script (and guesses the format of POST request) can submit bugs!

There are many possibilities of how to secure it (e.g. some kind of one time passwords, https, limiting the number of allowed submit from one IP address etc.).

Client side

The third (and last) thing is the code in our Eclipse plugin that handles exceptions and asks user if he wants to report them. We do this simply by listening to workspace log events and reporting (or asking user if he wants to report) if one of the following conditions holds:

  1. The plugin where an error occured is ours
  2. The exception stacktrace contains our class

We consider plugin or class “ours” if its name starts with “com.our-company.productname”. The following code must be run at startup (see how to do it):
[java]
Platform.addLogListener(new ILogListener(){
public void logging(IStatus status, String plugin) {
//1. check plugin name

//2. check the stack trace
if (status.getException() != null) {
//process status.getException().getStackTrace()…
}

//if we are interested in this error and user agrres
//do POST request with description set
//to our php script URL
}
}
[/java]

And that’s probably all 😉

Tags: , , , , , , ,

One Response to “Tips on developing Eclipse plugins – VI. – Automatic exception reporting to Bugzilla”

  1. Donald says:

    I just want to share the tool we’re using for tracking bugs http://www.wrike.com. The tool allows you to send screenshots to your team and get them in to your bug fixing plan at the same time. It’s all done via emails. Saves tons of time!