Cubus Arts Blog

/ ruby
Mihai Târnovan

Installing mysql gem with Percona XtraDB

Mihai Târnovan

After installing the mysql gem, we were seeing uninitialized constant MysqlCompat::MysqlRes errors all over the place, although the gem installed fine.

This was on FreeBSD 8.1. Turns out Percona XtraDB binary doesn’t include the mysql client libs, so you need to install those as well. On FreeBSD just do

pkg_add -r mysql51-client

Then reinstall the gem:

env ARCHFLAGS="-arch x86_64" gem i mysql -- --with-mysql-config=/usr/local/percona-xtradb/bin/mysql_config

Mihai Târnovan

Ruby Eval stacktrace position information

Mihai Târnovan

We’ve been often annoyed by warnings or exceptions like this: (eval):231: some error or warning. They make it very difficult to pinpoint the exact location of the problem.

The problem is usually cause by module_eval being called without file and line information. There’s an interesting write-up about eval and position information on Ola Bini’s blog. One of his readers observed that when using module_eval like this you’ll get the incorrect line number:

However, I noticed that if you write the heredoc inline you’ll get the correct line in the backtrace:

__LINE__ + 1 accounts for the line with the module_eval itself. I tested this with Ruby 1.8.6 and Ruby 1.9.1 and it applies for both, tough 1.9 at least puts more lines in the backtrace with the position of the module_eval call.

Passing __FILE__ and __LINE__ is better than skipping them, but can lead to false line numbers unless you use the 2nd form with the inlined heredoc.