How to handle "UserData" in errors

John Arbash Meinel john at arbash-meinel.com
Tue Feb 19 07:32:55 UTC 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Right now when we generate error messages, we include the context of
the request that we sent. Which is often quite helpful. However one of
those values is a "UserData []byte" which contains a fair sized data
array (2kb?) of compressed data.

When Go reports on that array, it turns it into [0x64, 0xf6, 0x1f,
...]. So every byte of the array becomes ~5 bytes in the terminal.

I'd like to keep it in, in case you want to grab that, decompress it,
and make sure it makes sense. But it *really* clutters the terminal
and makes it hard to find the actual problems.

This seems to be because of the default formatting for Error(), is
there an obvious/straightforward way to change it so we can do
something like include UserData as a base64 string instead of hex escapes?

And one step further, it seems if you use:

  c.Assert(err, IsNil)

Then you actually end up getting the error written *2* times to the
output. It looks like that is because we have the value of UserData in
the struct (so gocheck formats the struct to the output) and then we
also have the value of UserData in Error() (so gocheck prints Error()
as well.)

Is there a way to control the formatting used by gocheck for the
struct itself? If not, we could minimize this a bit by controlling
what we put into Error().

However, I think we want the contents in Error() (properly formatted)
because I think that is what we will log when something goes wrong,
which is where you really want the content.

Is the only option a custom matcher for gocheck?

See http://paste.ubuntu.com/1680333/ for how I tried sorting out where
the various strings were coming from.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.13 (Cygwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlEjKqcACgkQJdeBCYSNAAMeLACgmZ85l85YJWa6N44TActEryTy
xqEAn1leXkifTVXJE5OJLlxrfeSvQdb/
=vU3v
-----END PGP SIGNATURE-----



More information about the Juju-dev mailing list