Converted panic to an error

https://code.google.com/p/go-wiki/wiki/PanicAndRecover

By convention, no explicit panic() should be allowed to cross a package boundary. Indicating error conditions to callers should be done by returning error value.