Skip to content

Commit 377b39f

Browse files
committed
CSHARP-1134: Add Mongo prefix to exception class names that didn't already have it.
1 parent a88c99e commit 377b39f

28 files changed

+321
-114
lines changed

MongoDB.Driver/Exceptions/BulkWriteException.cs

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,17 @@ namespace MongoDB.Driver
2525
/// Represents a bulk write exception.
2626
/// </summary>
2727
[Serializable]
28-
public class BulkWriteException : MongoException
28+
[Obsolete("Use MongoBulkWriteException instead.")]
29+
public abstract class BulkWriteException : MongoException
2930
{
30-
// private fields
31-
private BulkWriteResult _result;
32-
private ReadOnlyCollection<WriteRequest> _unprocessedRequests;
33-
private WriteConcernError _writeConcernError;
34-
private ReadOnlyCollection<BulkWriteError> _writeErrors;
35-
3631
// constructors
3732
/// <summary>
3833
/// Initializes a new instance of the <see cref="BulkWriteException" /> class.
3934
/// </summary>
40-
/// <param name="result">The result.</param>
41-
/// <param name="writeErrors">The write errors.</param>
42-
/// <param name="unprocessedRequests">The unprocessed requests.</param>
43-
/// <param name="writeConcernError">The write concern error.</param>
44-
public BulkWriteException(
45-
BulkWriteResult result,
46-
IEnumerable<BulkWriteError> writeErrors,
47-
WriteConcernError writeConcernError,
48-
IEnumerable<WriteRequest> unprocessedRequests)
49-
: base("A bulk write operation resulted in one or more errors.")
35+
/// <param name="message">The error message.</param>
36+
public BulkWriteException(string message)
37+
: base(message)
5038
{
51-
_result = result;
52-
_writeErrors = new ReadOnlyCollection<BulkWriteError>(writeErrors.ToList());
53-
_writeConcernError = writeConcernError;
54-
_unprocessedRequests = new ReadOnlyCollection<WriteRequest>(unprocessedRequests.ToList());
5539
}
5640

5741
/// <summary>
@@ -68,10 +52,7 @@ public BulkWriteException(SerializationInfo info, StreamingContext context)
6852
/// <summary>
6953
/// Gets the result of the bulk write operation.
7054
/// </summary>
71-
public BulkWriteResult Result
72-
{
73-
get { return _result; }
74-
}
55+
public abstract BulkWriteResult Result { get; }
7556

7657
/// <summary>
7758
/// Gets the unprocessed requests.
@@ -80,31 +61,22 @@ public BulkWriteResult Result
8061
/// The unprocessed requests.
8162
/// </value>
8263
/// <exception cref="System.NotImplementedException"></exception>
83-
public ReadOnlyCollection<WriteRequest> UnprocessedRequests
84-
{
85-
get { return _unprocessedRequests; }
86-
}
64+
public abstract ReadOnlyCollection<WriteRequest> UnprocessedRequests { get; }
8765

8866
/// <summary>
8967
/// Gets the write concern error.
9068
/// </summary>
9169
/// <value>
9270
/// The write concern error.
9371
/// </value>
94-
public WriteConcernError WriteConcernError
95-
{
96-
get { return _writeConcernError; }
97-
}
72+
public abstract WriteConcernError WriteConcernError { get; }
9873

9974
/// <summary>
10075
/// Gets the write errors.
10176
/// </summary>
10277
/// <value>
10378
/// The write errors.
10479
/// </value>
105-
public ReadOnlyCollection<BulkWriteError> WriteErrors
106-
{
107-
get { return _writeErrors; }
108-
}
80+
public abstract ReadOnlyCollection<BulkWriteError> WriteErrors { get; }
10981
}
11082
}

MongoDB.Driver/Exceptions/ExceptionMapper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static Exception Map(BsonDocument response)
4040
case 13475:
4141
case 16986:
4242
case 16712:
43-
return new ExecutionTimeoutException("Operation exceeded time limit.");
43+
return new MongoExecutionTimeoutException("Operation exceeded time limit.");
4444
}
4545
}
4646

@@ -51,7 +51,7 @@ public static Exception Map(BsonDocument response)
5151
if (errmsg.AsString.Contains("exceeded time limit") ||
5252
errmsg.AsString.Contains("execution terminated"))
5353
{
54-
return new ExecutionTimeoutException("Operation exceeded time limit.");
54+
return new MongoExecutionTimeoutException("Operation exceeded time limit.");
5555
}
5656
}
5757

@@ -87,7 +87,7 @@ public static Exception Map(WriteConcernResult writeConcernResult)
8787
var errorMessage = string.Format(
8888
"WriteConcern detected an error '{0}'. (Response was {1}).",
8989
writeConcernResult.ErrorMessage, writeConcernResult.Response.ToJson());
90-
return new WriteConcernException(errorMessage, writeConcernResult);
90+
return new MongoWriteConcernException(errorMessage, writeConcernResult);
9191
}
9292

9393
if (writeConcernResult.HasLastErrorMessage)
@@ -96,7 +96,7 @@ public static Exception Map(WriteConcernResult writeConcernResult)
9696
"WriteConcern detected an error '{0}'. (Response was {1}).",
9797
writeConcernResult.LastErrorMessage,
9898
writeConcernResult.Response.ToJson());
99-
return new WriteConcernException(errorMessage, writeConcernResult);
99+
return new MongoWriteConcernException(errorMessage, writeConcernResult);
100100
}
101101

102102
return null;

MongoDB.Driver/Exceptions/ExecutionTimeoutException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace MongoDB.Driver
2222
/// Represents a MongoDB execution timeout exception.
2323
/// </summary>
2424
[Serializable]
25-
public class ExecutionTimeoutException : MongoException
25+
[Obsolete("Use MongoExecutionTimeoutException instead.")]
26+
public abstract class ExecutionTimeoutException : MongoException
2627
{
2728
// constructors
2829
/// <summary>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/* Copyright 2010-2014 MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Collections.ObjectModel;
19+
using System.Linq;
20+
using System.Runtime.Serialization;
21+
22+
namespace MongoDB.Driver
23+
{
24+
/// <summary>
25+
/// Represents a bulk write exception.
26+
/// </summary>
27+
[Serializable]
28+
#pragma warning disable 618
29+
public class MongoBulkWriteException : BulkWriteException
30+
#pragma warning restore
31+
{
32+
// private fields
33+
private BulkWriteResult _result;
34+
private ReadOnlyCollection<WriteRequest> _unprocessedRequests;
35+
private WriteConcernError _writeConcernError;
36+
private ReadOnlyCollection<BulkWriteError> _writeErrors;
37+
38+
// constructors
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="MongoBulkWriteException" /> class.
41+
/// </summary>
42+
/// <param name="result">The result.</param>
43+
/// <param name="writeErrors">The write errors.</param>
44+
/// <param name="unprocessedRequests">The unprocessed requests.</param>
45+
/// <param name="writeConcernError">The write concern error.</param>
46+
public MongoBulkWriteException(
47+
BulkWriteResult result,
48+
IEnumerable<BulkWriteError> writeErrors,
49+
WriteConcernError writeConcernError,
50+
IEnumerable<WriteRequest> unprocessedRequests)
51+
: base("A bulk write operation resulted in one or more errors.")
52+
{
53+
_result = result;
54+
_writeErrors = new ReadOnlyCollection<BulkWriteError>(writeErrors.ToList());
55+
_writeConcernError = writeConcernError;
56+
_unprocessedRequests = new ReadOnlyCollection<WriteRequest>(unprocessedRequests.ToList());
57+
}
58+
59+
/// <summary>
60+
/// Initializes a new instance of the MongoBulkWriteException class (this overload supports deserialization).
61+
/// </summary>
62+
/// <param name="info">The SerializationInfo.</param>
63+
/// <param name="context">The StreamingContext.</param>
64+
public MongoBulkWriteException(SerializationInfo info, StreamingContext context)
65+
: base(info, context)
66+
{
67+
}
68+
69+
// public properties
70+
/// <summary>
71+
/// Gets the result of the bulk write operation.
72+
/// </summary>
73+
public override BulkWriteResult Result
74+
{
75+
get { return _result; }
76+
}
77+
78+
/// <summary>
79+
/// Gets the unprocessed requests.
80+
/// </summary>
81+
/// <value>
82+
/// The unprocessed requests.
83+
/// </value>
84+
/// <exception cref="System.NotImplementedException"></exception>
85+
public override ReadOnlyCollection<WriteRequest> UnprocessedRequests
86+
{
87+
get { return _unprocessedRequests; }
88+
}
89+
90+
/// <summary>
91+
/// Gets the write concern error.
92+
/// </summary>
93+
/// <value>
94+
/// The write concern error.
95+
/// </value>
96+
public override WriteConcernError WriteConcernError
97+
{
98+
get { return _writeConcernError; }
99+
}
100+
101+
/// <summary>
102+
/// Gets the write errors.
103+
/// </summary>
104+
/// <value>
105+
/// The write errors.
106+
/// </value>
107+
public override ReadOnlyCollection<BulkWriteError> WriteErrors
108+
{
109+
get { return _writeErrors; }
110+
}
111+
}
112+
}

MongoDB.Driver/Exceptions/MongoDuplicateKeyException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace MongoDB.Driver
2020
/// <summary>
2121
/// Thrown when a duplicate key is inserted into a collection.
2222
/// </summary>
23-
public class MongoDuplicateKeyException : WriteConcernException
23+
public class MongoDuplicateKeyException : MongoWriteConcernException
2424
{
2525
/// <summary>
2626
/// Initializes a new instance of the <see cref="MongoDuplicateKeyException"/> class.
@@ -33,7 +33,7 @@ public MongoDuplicateKeyException(string message, WriteConcernResult commandResu
3333
}
3434

3535
/// <summary>
36-
/// Initializes a new instance of the WriteConcernException class (this overload supports deserialization).
36+
/// Initializes a new instance of the MongoDuplicateKeyException class (this overload supports deserialization).
3737
/// </summary>
3838
/// <param name="info">The SerializationInfo.</param>
3939
/// <param name="context">The StreamingContext.</param>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* Copyright 2010-2014 MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Runtime.Serialization;
18+
19+
namespace MongoDB.Driver
20+
{
21+
/// <summary>
22+
/// Represents a MongoDB execution timeout exception.
23+
/// </summary>
24+
[Serializable]
25+
#pragma warning disable 618
26+
public class MongoExecutionTimeoutException : ExecutionTimeoutException
27+
#pragma warning restore
28+
{
29+
// constructors
30+
/// <summary>
31+
/// Initializes a new instance of the MongoExecutionTimeoutException class.
32+
/// </summary>
33+
/// <param name="message">The error message.</param>
34+
public MongoExecutionTimeoutException(string message)
35+
: base(message)
36+
{
37+
}
38+
39+
/// <summary>
40+
/// Initializes a new instance of the MongoExecutionTimeoutException class.
41+
/// </summary>
42+
/// <param name="message">The error message.</param>
43+
/// <param name="innerException">The inner exception.</param>
44+
public MongoExecutionTimeoutException(string message, Exception innerException)
45+
: base(message, innerException)
46+
{
47+
}
48+
49+
/// <summary>
50+
/// Initializes a new instance of the MongoExecutionTimeoutException class (this overload supports deserialization).
51+
/// </summary>
52+
/// <param name="info">The SerializationInfo.</param>
53+
/// <param name="context">The StreamingContext.</param>
54+
public MongoExecutionTimeoutException(SerializationInfo info, StreamingContext context)
55+
: base(info, context)
56+
{
57+
}
58+
}
59+
}

MongoDB.Driver/Exceptions/MongoSafeModeException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace MongoDB.Driver
2222
/// Represents a MongoDB safe mode exception.
2323
/// </summary>
2424
[Serializable]
25-
[Obsolete("Use WriteConcernException instead.")]
25+
[Obsolete("Use MongoWriteConcernException instead.")]
2626
public class MongoSafeModeException : MongoCommandException
2727
{
2828
// constructors
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* Copyright 2010-2014 MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Runtime.Serialization;
18+
19+
namespace MongoDB.Driver
20+
{
21+
/// <summary>
22+
/// Represents a write concern exception.
23+
/// </summary>
24+
[Serializable]
25+
#pragma warning disable 618
26+
public class MongoWriteConcernException : WriteConcernException
27+
#pragma warning restore
28+
{
29+
// constructors
30+
/// <summary>
31+
/// Initializes a new instance of the MongoWriteConcernException class.
32+
/// </summary>
33+
/// <param name="message">The error message.</param>
34+
/// <param name="writeConcernResult">The command result.</param>
35+
public MongoWriteConcernException(string message, WriteConcernResult writeConcernResult)
36+
: base(message, writeConcernResult)
37+
{
38+
}
39+
40+
/// <summary>
41+
/// Initializes a new instance of the MongoWriteConcernException class (this overload supports deserialization).
42+
/// </summary>
43+
/// <param name="info">The SerializationInfo.</param>
44+
/// <param name="context">The StreamingContext.</param>
45+
public MongoWriteConcernException(SerializationInfo info, StreamingContext context)
46+
: base(info, context)
47+
{
48+
}
49+
50+
// public properties
51+
/// <summary>
52+
/// Gets the write concern result.
53+
/// </summary>
54+
/// <value>
55+
/// The write concern result.
56+
/// </value>
57+
public override WriteConcernResult WriteConcernResult
58+
{
59+
#pragma warning disable 618
60+
get { return (WriteConcernResult)CommandResult; }
61+
#pragma warning restore
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)