From 2796ef9137511919936df57286babf0dd52d498b Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Tue, 5 Sep 2017 16:26:34 -0700 Subject: [PATCH] Document QueryError Also give an example of an error returned as a QueryError in production, so you can see what e.g. the Message field may look like. --- example_test.go | 14 ++++++++++++++ session.go | 3 +++ 2 files changed, 17 insertions(+) create mode 100644 example_test.go diff --git a/example_test.go b/example_test.go new file mode 100644 index 000000000..f443f49c3 --- /dev/null +++ b/example_test.go @@ -0,0 +1,14 @@ +package mgo + +import "fmt" + +func ExampleQueryError() { + e := &QueryError{ + Code: 17406, + Message: "getMore executor error: CappedPositionLost: CollectionScan died due to failure to restore tailable cursor position. Last seen record id: RecordId(200138)", + Assertion: false, + } + fmt.Println(e.String()) + // Output: + // getMore executor error: CappedPositionLost: CollectionScan died due to failure to restore tailable cursor position. Last seen record id: RecordId(200138) +} diff --git a/session.go b/session.go index 5801e225c..b24ddcc77 100644 --- a/session.go +++ b/session.go @@ -2397,7 +2397,10 @@ type queryError struct { AssertionCode int "assertionCode" } +// QueryError indicates an error that occurred during a Mongo query. type QueryError struct { + // A list of codes can be found here: + // https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.err Code int Message string Assertion bool