Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4545)

Issue 87560043: errors: Improve tests, unify interfaces, wrapping (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years ago by dimitern
Modified:
10 years ago
Reviewers:
mp+215652, fwereade, rog
Visibility:
Public.

Description

errors: Improve tests, unify interfaces, wrapping The errors package is refactored so that for all errors defined there are 3 functions with consistent names: * Is<type>(error) bool Returns true if the error satifies <type> (i.e. it was created with one of the two constructors below for <type>. * New<type>(error, string) error Creates an error of <type> wrapping the given error and adding the prefix to the message. * <type>f(string, ...interface{}) error Creates an error of <type> with a message, formatted like fmt.Sprintf. Dropped "Error" from type and function names (as they already are in the "errors" package). Moved utils.ErrorContextf in here, renaming it to Maskf. A new helper called Contextf is added, which works similarly to Maskf, but preserves the original error when wrapping (if it's one of the known types), so that the Is<type>() satifiers will work on the wrapped error as well. Added automatic exhaustive testing for each error type in a way that makes it easier to add new types. Few drive-by fixes made while fixing the rest of the code base to use the new function names. I realize we should use errgo for such things, but we can easily change the errors package to use errgo internally later. https://code.launchpad.net/~dimitern/juju-core/396-improve-errors/+merge/215652 (do not edit description out of merge proposal)

Patch Set 1 #

Total comments: 6

Patch Set 2 : errors: Improve tests, unify interfaces, wrapping #

Total comments: 12

Patch Set 3 : errors: Improve tests, unify interfaces, wrapping #

Total comments: 4

Patch Set 4 : errors: Improve tests, unify interfaces, wrapping #

Unified diffs Side-by-side diffs Delta from patch set Stats (+689 lines, -551 lines) Patch
A [revision details] View 1 2 3 1 chunk +2 lines, -0 lines 0 comments Download
M cmd/juju/common.go View 1 chunk +1 line, -1 line 0 comments Download
M cmd/juju/debuglog.go View 1 chunk +1 line, -1 line 0 comments Download
M cmd/juju/debuglog_test.go View 1 chunk +1 line, -1 line 0 comments Download
M cmd/juju/deploy_test.go View 1 chunk +1 line, -1 line 0 comments Download
M cmd/juju/destroyenvironment_test.go View 3 chunks +3 lines, -3 lines 0 comments Download
M cmd/juju/destroymachine_test.go View 1 chunk +1 line, -1 line 0 comments Download
M cmd/jujud/machine.go View 1 2 2 chunks +2 lines, -2 lines 0 comments Download
M cmd/jujud/machine_test.go View 1 2 3 chunks +3 lines, -3 lines 0 comments Download
M container/lxc/instance.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/bootstrap/state.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/bootstrap/synctools.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/cloudinit.go View 1 2 2 chunks +2 lines, -1 line 0 comments Download
M environs/cloudinit/cloudinit.go View 1 2 2 chunks +2 lines, -1 line 0 comments Download
M environs/configstore/disk_test.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/filestorage/filestorage.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/filestorage/filestorage_test.go View 1 chunk +4 lines, -4 lines 0 comments Download
M environs/httpstorage/storage_test.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/imagemetadata/generate.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/jujutest/livetests.go View 3 chunks +3 lines, -3 lines 0 comments Download
M environs/jujutest/tests.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/open.go View 3 chunks +3 lines, -3 lines 0 comments Download
M environs/open_test.go View 2 chunks +2 lines, -2 lines 0 comments Download
M environs/simplestreams/simplestreams.go View 6 chunks +6 lines, -6 lines 0 comments Download
M environs/sshstorage/storage.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/sshstorage/storage_test.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/tools/simplestreams.go View 1 chunk +1 line, -1 line 0 comments Download
M environs/tools/tools.go View 2 chunks +2 lines, -2 lines 0 comments Download
M environs/tools/tools_test.go View 5 chunks +5 lines, -5 lines 0 comments Download
M errors/errors.go View 1 2 1 chunk +182 lines, -130 lines 0 comments Download
M errors/errors_test.go View 1 2 3 2 chunks +174 lines, -87 lines 0 comments Download
M juju/api.go View 1 2 3 chunks +3 lines, -3 lines 0 comments Download
M juju/conn.go View 1 2 2 chunks +2 lines, -2 lines 0 comments Download
M juju/conn_test.go View 1 chunk +1 line, -1 line 0 comments Download
M provider/azure/certfile.go View 1 2 2 chunks +2 lines, -2 lines 0 comments Download
M provider/azure/instancetype.go View 1 chunk +1 line, -1 line 0 comments Download
M provider/azure/storage_test.go View 1 chunk +1 line, -1 line 0 comments Download
M provider/common/destroy_test.go View 2 chunks +2 lines, -2 lines 0 comments Download
M provider/ec2/storage.go View 1 chunk +1 line, -1 line 0 comments Download
M provider/joyent/storage.go View 2 chunks +2 lines, -2 lines 0 comments Download
M provider/joyent/storage_test.go View 2 chunks +2 lines, -2 lines 0 comments Download
M provider/local/instance.go View 1 chunk +1 line, -1 line 0 comments Download
M provider/maas/environ_whitebox_test.go View 1 chunk +1 line, -1 line 0 comments Download
M provider/maas/storage.go View 1 chunk +4 lines, -3 lines 0 comments Download
M provider/maas/storage_test.go View 3 chunks +3 lines, -3 lines 0 comments Download
M provider/openstack/storage.go View 1 chunk +1 line, -1 line 0 comments Download
M state/addmachine.go View 1 2 3 chunks +2 lines, -3 lines 0 comments Download
M state/annotator.go View 1 2 2 chunks +2 lines, -2 lines 0 comments Download
M state/api/agent/machine_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/api/client.go View 1 chunk +9 lines, -5 lines 0 comments Download
M state/api/machiner/machiner_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/api/params/apierror.go View 1 chunk +5 lines, -4 lines 0 comments Download
M state/api/provisioner/provisioner_test.go View 2 chunks +3 lines, -3 lines 0 comments Download
M state/api/uniter/relation.go View 1 chunk +2 lines, -2 lines 0 comments Download
M state/api/uniter/unit_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/api/upgrader/unitupgrader_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/api/upgrader/upgrader_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/apiserver/admin.go View 1 chunk +1 line, -1 line 0 comments Download
M state/apiserver/charmrevisionupdater/updater_test.go View 1 2 3 chunks +5 lines, -5 lines 0 comments Download
M state/apiserver/client/api_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/apiserver/client/client.go View 1 2 4 chunks +4 lines, -4 lines 0 comments Download
M state/apiserver/client/client_test.go View 1 2 7 chunks +8 lines, -8 lines 0 comments Download
M state/apiserver/client/destroy_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/apiserver/client/status.go View 1 2 2 chunks +2 lines, -2 lines 0 comments Download
M state/apiserver/common/errors.go View 1 chunk +3 lines, -3 lines 0 comments Download
M state/apiserver/common/errors_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/apiserver/deployer/deployer_test.go View 1 2 4 chunks +4 lines, -3 lines 0 comments Download
M state/apiserver/firewaller/firewaller_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/apiserver/keymanager/keymanager.go View 1 chunk +1 line, -1 line 0 comments Download
M state/apiserver/keyupdater/authorisedkeys.go View 2 chunks +2 lines, -2 lines 0 comments Download
M state/apiserver/machine/machiner.go View 1 chunk +1 line, -1 line 0 comments Download
M state/apiserver/provisioner/provisioner_test.go View 1 2 2 chunks +2 lines, -2 lines 0 comments Download
M state/apiserver/uniter/uniter.go View 4 chunks +4 lines, -4 lines 0 comments Download
M state/apiserver/uniter/uniter_test.go View 1 2 2 chunks +3 lines, -3 lines 0 comments Download
M state/apiserver/upgrader/unitupgrader_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/apiserver/upgrader/upgrader_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/apiserver/usermanager/usermanager.go View 1 2 1 chunk +2 lines, -1 line 0 comments Download
M state/apiserver/usermanager/usermanager_test.go View 1 2 1 chunk +1 line, -1 line 0 comments Download
M state/charm_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/cleanup.go View 6 chunks +6 lines, -6 lines 0 comments Download
M state/cleanup_test.go View 3 chunks +4 lines, -4 lines 0 comments Download
M state/configvalidator_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/conn_test.go View 1 chunk +3 lines, -3 lines 0 comments Download
M state/environcapability_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/machine.go View 1 2 17 chunks +20 lines, -21 lines 0 comments Download
M state/machine_test.go View 4 chunks +7 lines, -7 lines 0 comments Download
M state/megawatcher.go View 1 chunk +1 line, -1 line 0 comments Download
M state/minimumunits.go View 1 2 3 chunks +3 lines, -3 lines 0 comments Download
M state/open.go View 1 2 1 chunk +1 line, -1 line 0 comments Download
M state/policy.go View 3 chunks +3 lines, -3 lines 0 comments Download
M state/prechecker_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/relation.go View 1 2 4 chunks +4 lines, -5 lines 0 comments Download
M state/relation_test.go View 4 chunks +6 lines, -6 lines 0 comments Download
M state/relationunit.go View 1 2 3 chunks +2 lines, -3 lines 0 comments Download
M state/relationunit_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/service.go View 1 2 8 chunks +8 lines, -9 lines 0 comments Download
M state/service_test.go View 11 chunks +14 lines, -14 lines 0 comments Download
M state/settings_test.go View 2 chunks +2 lines, -2 lines 0 comments Download
M state/state.go View 1 2 8 chunks +9 lines, -11 lines 0 comments Download
M state/state_test.go View 1 2 17 chunks +19 lines, -19 lines 0 comments Download
M state/tools_test.go View 1 chunk +1 line, -1 line 0 comments Download
M state/unit.go View 1 2 13 chunks +15 lines, -13 lines 0 comments Download
M state/unit_test.go View 7 chunks +9 lines, -9 lines 0 comments Download
M state/watcher.go View 1 chunk +1 line, -1 line 0 comments Download
M utils/trivial.go View 2 chunks +0 lines, -11 lines 0 comments Download
M worker/deployer/deployer_test.go View 1 chunk +1 line, -1 line 0 comments Download
M worker/instancepoller/machine_test.go View 1 chunk +1 line, -1 line 0 comments Download
M worker/instancepoller/updater.go View 3 chunks +3 lines, -3 lines 0 comments Download
M worker/peergrouper/worker.go View 2 chunks +2 lines, -2 lines 0 comments Download
M worker/provisioner/kvm-broker_test.go View 1 2 1 chunk +1 line, -1 line 0 comments Download
M worker/provisioner/lxc-broker_test.go View 1 2 1 chunk +1 line, -1 line 0 comments Download
M worker/provisioner/provisioner.go View 2 chunks +2 lines, -2 lines 0 comments Download
M worker/provisioner/provisioner_test.go View 2 chunks +3 lines, -3 lines 0 comments Download
M worker/uniter/charm/bundles.go View 1 2 2 chunks +2 lines, -1 line 0 comments Download
M worker/uniter/relation/relation.go View 1 2 5 chunks +5 lines, -4 lines 0 comments Download
M worker/uniter/relationer_test.go View 1 chunk +1 line, -1 line 0 comments Download
M worker/uniter/state.go View 1 2 2 chunks +2 lines, -1 line 0 comments Download
M worker/uniter/uniter_test.go View 3 chunks +3 lines, -3 lines 0 comments Download
M worker/upgrader/upgrader_test.go View 3 chunks +4 lines, -4 lines 0 comments Download

Messages

Total messages: 9
dimitern
Please take a look.
10 years ago (2014-04-14 12:51:36 UTC) #1
rog
Big +1 to the renaming improvements. I haven't looked at anything apart from errors.go, but ...
10 years ago (2014-04-14 13:21:37 UTC) #2
dimitern
Please take a look. https://codereview.appspot.com/87560043/diff/1/errors/errors.go File errors/errors.go (right): https://codereview.appspot.com/87560043/diff/1/errors/errors.go#newcode13 errors/errors.go:13: Err error On 2014/04/14 13:21:38, ...
10 years ago (2014-04-14 13:44:26 UTC) #3
rog
On further reflection, I'm not convinced that this change is benign. Currently anywhere that uses ...
10 years ago (2014-04-14 18:19:27 UTC) #4
fwereade
On 2014/04/14 18:19:27, rog wrote: > On further reflection, I'm not convinced that this change ...
10 years ago (2014-04-17 09:55:35 UTC) #5
rog
On 17 April 2014 10:55, <fwereade@gmail.com> wrote: > On 2014/04/14 18:19:27, rog wrote: >> >> ...
10 years ago (2014-04-17 12:19:19 UTC) #6
dimitern
Please take a look. https://codereview.appspot.com/87560043/diff/2/errors/errors.go File errors/errors.go (right): https://codereview.appspot.com/87560043/diff/2/errors/errors.go#newcode60 errors/errors.go:60: *wrapper On 2014/04/14 18:19:28, rog ...
10 years ago (2014-04-17 13:12:58 UTC) #7
rog
LGTM - tests are much improved, thanks. https://codereview.appspot.com/87560043/diff/20001/errors/errors_test.go File errors/errors_test.go (right): https://codereview.appspot.com/87560043/diff/20001/errors/errors_test.go#newcode94 errors/errors_test.go:94: c.Check(message, gc.Equals, ...
10 years ago (2014-04-17 14:44:40 UTC) #8
dimitern
10 years ago (2014-04-17 15:04:33 UTC) #9
Please take a look.

https://codereview.appspot.com/87560043/diff/20001/errors/errors_test.go
File errors/errors_test.go (right):

https://codereview.appspot.com/87560043/diff/20001/errors/errors_test.go#newc...
errors/errors_test.go:94: c.Check(message, gc.Equals, "<nil>")
On 2014/04/17 14:44:40, rog wrote:
> neither of the two checks above are testing anything apart from what's in the
> test.
> 
> it seems a bit odd that what we check is depending on the
> err value, not our expected value.
> 
> i'd expect to see something more like this:
> 
> func checkErrorMatches(c *gc.C, err error, message string) {
>     if message == "" {
>         c.Assert(err, gc.Equals, nil)
>     } else {
>         c.Assert(err, gc.ErrorMatches, message)
>     }
> }

Done similarly: kept "<nil>" as a special message value to distinguish between
"empty message, but err != nil" and "empty message, err == nil". Also improved
and further simplified all 3 test cases.

https://codereview.appspot.com/87560043/diff/20001/errors/errors_test.go#newc...
errors/errors_test.go:131: mustNotSatisfy(c, t.err, t.errInfo)
On 2014/04/17 14:44:40, rog wrote:
> isn't this checked below?

It is actually, dropped.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b