Skip to content

Commit 6b7dbaf

Browse files
committed
Improve error message for invalid endpoint argument.
1 parent 219354e commit 6b7dbaf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+308
-155
lines changed

Dropbox.Api/Async/PollArg.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public PollArg(string asyncJobId)
3838
{
3939
throw new sys.ArgumentNullException("asyncJobId");
4040
}
41-
else if (asyncJobId.Length < 1)
41+
if (asyncJobId.Length < 1)
4242
{
43-
throw new sys.ArgumentOutOfRangeException("asyncJobId");
43+
throw new sys.ArgumentOutOfRangeException("asyncJobId", "Length should be at least 1");
4444
}
4545

4646
this.AsyncJobId = asyncJobId;

Dropbox.Api/Files/CommitInfo.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,15 @@ public CommitInfo(string path,
5555
{
5656
throw new sys.ArgumentNullException("path");
5757
}
58-
else if (!re.Regex.IsMatch(path, @"\A(?:/.*)\z"))
58+
if (!re.Regex.IsMatch(path, @"\A(?:/.*)\z"))
5959
{
60-
throw new sys.ArgumentOutOfRangeException("path");
60+
throw new sys.ArgumentOutOfRangeException("path", @"Value should match pattern '\A(?:/.*)\z'");
6161
}
6262

6363
if (mode == null)
6464
{
6565
mode = WriteMode.Add.Instance;
6666
}
67-
6867
this.Path = path;
6968
this.Mode = mode;
7069
this.Autorename = autorename;

Dropbox.Api/Files/CreateFolderArg.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public CreateFolderArg(string path)
3838
{
3939
throw new sys.ArgumentNullException("path");
4040
}
41-
else if (!re.Regex.IsMatch(path, @"\A(?:/.*)\z"))
41+
if (!re.Regex.IsMatch(path, @"\A(?:/.*)\z"))
4242
{
43-
throw new sys.ArgumentOutOfRangeException("path");
43+
throw new sys.ArgumentOutOfRangeException("path", @"Value should match pattern '\A(?:/.*)\z'");
4444
}
4545

4646
this.Path = path;

Dropbox.Api/Files/DeleteArg.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public DeleteArg(string path)
3737
{
3838
throw new sys.ArgumentNullException("path");
3939
}
40-
else if (!re.Regex.IsMatch(path, @"\A(?:/.*)\z"))
40+
if (!re.Regex.IsMatch(path, @"\A(?:/.*)\z"))
4141
{
42-
throw new sys.ArgumentOutOfRangeException("path");
42+
throw new sys.ArgumentOutOfRangeException("path", @"Value should match pattern '\A(?:/.*)\z'");
4343
}
4444

4545
this.Path = path;

Dropbox.Api/Files/DownloadArg.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,21 @@ public DownloadArg(string path,
4040
{
4141
throw new sys.ArgumentNullException("path");
4242
}
43-
else if (!re.Regex.IsMatch(path, @"\A(?:((/|id:).*)|(rev:[0-9a-f]{9,}))\z"))
43+
if (!re.Regex.IsMatch(path, @"\A(?:((/|id:).*)|(rev:[0-9a-f]{9,}))\z"))
4444
{
45-
throw new sys.ArgumentOutOfRangeException("path");
45+
throw new sys.ArgumentOutOfRangeException("path", @"Value should match pattern '\A(?:((/|id:).*)|(rev:[0-9a-f]{9,}))\z'");
4646
}
4747

48-
if (rev != null && (rev.Length < 9 || !re.Regex.IsMatch(rev, @"\A(?:[0-9a-f]+)\z")))
48+
if (rev != null)
4949
{
50-
throw new sys.ArgumentOutOfRangeException("rev");
50+
if (rev.Length < 9)
51+
{
52+
throw new sys.ArgumentOutOfRangeException("rev", "Length should be at least 9");
53+
}
54+
if (!re.Regex.IsMatch(rev, @"\A(?:[0-9a-f]+)\z"))
55+
{
56+
throw new sys.ArgumentOutOfRangeException("rev", @"Value should match pattern '\A(?:[0-9a-f]+)\z'");
57+
}
5158
}
5259

5360
this.Path = path;

Dropbox.Api/Files/FileMetadata.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,22 @@ public FileMetadata(string name,
7575
{
7676
throw new sys.ArgumentNullException("id");
7777
}
78-
else if (id.Length < 1)
78+
if (id.Length < 1)
7979
{
80-
throw new sys.ArgumentOutOfRangeException("id");
80+
throw new sys.ArgumentOutOfRangeException("id", "Length should be at least 1");
8181
}
8282

8383
if (rev == null)
8484
{
8585
throw new sys.ArgumentNullException("rev");
8686
}
87-
else if (rev.Length < 9 || !re.Regex.IsMatch(rev, @"\A(?:[0-9a-f]+)\z"))
87+
if (rev.Length < 9)
8888
{
89-
throw new sys.ArgumentOutOfRangeException("rev");
89+
throw new sys.ArgumentOutOfRangeException("rev", "Length should be at least 9");
90+
}
91+
if (!re.Regex.IsMatch(rev, @"\A(?:[0-9a-f]+)\z"))
92+
{
93+
throw new sys.ArgumentOutOfRangeException("rev", @"Value should match pattern '\A(?:[0-9a-f]+)\z'");
9094
}
9195

9296
this.Id = id;

Dropbox.Api/Files/FileSharingInfo.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,21 @@ public FileSharingInfo(bool readOnly,
4747
{
4848
throw new sys.ArgumentNullException("parentSharedFolderId");
4949
}
50-
else if (!re.Regex.IsMatch(parentSharedFolderId, @"\A(?:[-_0-9a-zA-Z:]+)\z"))
50+
if (!re.Regex.IsMatch(parentSharedFolderId, @"\A(?:[-_0-9a-zA-Z:]+)\z"))
5151
{
52-
throw new sys.ArgumentOutOfRangeException("parentSharedFolderId");
52+
throw new sys.ArgumentOutOfRangeException("parentSharedFolderId", @"Value should match pattern '\A(?:[-_0-9a-zA-Z:]+)\z'");
5353
}
5454

55-
if (modifiedBy != null && (modifiedBy.Length < 40 || modifiedBy.Length > 40))
55+
if (modifiedBy != null)
5656
{
57-
throw new sys.ArgumentOutOfRangeException("modifiedBy");
57+
if (modifiedBy.Length < 40)
58+
{
59+
throw new sys.ArgumentOutOfRangeException("modifiedBy", "Length should be at least 40");
60+
}
61+
if (modifiedBy.Length > 40)
62+
{
63+
throw new sys.ArgumentOutOfRangeException("modifiedBy", "Length should be at most 40");
64+
}
5865
}
5966

6067
this.ParentSharedFolderId = parentSharedFolderId;

Dropbox.Api/Files/FolderMetadata.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ public FolderMetadata(string name,
6161
{
6262
throw new sys.ArgumentNullException("id");
6363
}
64-
else if (id.Length < 1)
64+
if (id.Length < 1)
6565
{
66-
throw new sys.ArgumentOutOfRangeException("id");
66+
throw new sys.ArgumentOutOfRangeException("id", "Length should be at least 1");
6767
}
6868

69-
if (sharedFolderId != null && (!re.Regex.IsMatch(sharedFolderId, @"\A(?:[-_0-9a-zA-Z:]+)\z")))
69+
if (sharedFolderId != null)
7070
{
71-
throw new sys.ArgumentOutOfRangeException("sharedFolderId");
71+
if (!re.Regex.IsMatch(sharedFolderId, @"\A(?:[-_0-9a-zA-Z:]+)\z"))
72+
{
73+
throw new sys.ArgumentOutOfRangeException("sharedFolderId", @"Value should match pattern '\A(?:[-_0-9a-zA-Z:]+)\z'");
74+
}
7275
}
7376

7477
this.Id = id;

Dropbox.Api/Files/FolderSharingInfo.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,20 @@ public FolderSharingInfo(bool readOnly,
4444
string sharedFolderId = null)
4545
: base(readOnly)
4646
{
47-
if (parentSharedFolderId != null && (!re.Regex.IsMatch(parentSharedFolderId, @"\A(?:[-_0-9a-zA-Z:]+)\z")))
47+
if (parentSharedFolderId != null)
4848
{
49-
throw new sys.ArgumentOutOfRangeException("parentSharedFolderId");
49+
if (!re.Regex.IsMatch(parentSharedFolderId, @"\A(?:[-_0-9a-zA-Z:]+)\z"))
50+
{
51+
throw new sys.ArgumentOutOfRangeException("parentSharedFolderId", @"Value should match pattern '\A(?:[-_0-9a-zA-Z:]+)\z'");
52+
}
5053
}
5154

52-
if (sharedFolderId != null && (!re.Regex.IsMatch(sharedFolderId, @"\A(?:[-_0-9a-zA-Z:]+)\z")))
55+
if (sharedFolderId != null)
5356
{
54-
throw new sys.ArgumentOutOfRangeException("sharedFolderId");
57+
if (!re.Regex.IsMatch(sharedFolderId, @"\A(?:[-_0-9a-zA-Z:]+)\z"))
58+
{
59+
throw new sys.ArgumentOutOfRangeException("sharedFolderId", @"Value should match pattern '\A(?:[-_0-9a-zA-Z:]+)\z'");
60+
}
5561
}
5662

5763
this.ParentSharedFolderId = parentSharedFolderId;

Dropbox.Api/Files/GetMetadataArg.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public GetMetadataArg(string path,
4141
{
4242
throw new sys.ArgumentNullException("path");
4343
}
44-
else if (!re.Regex.IsMatch(path, @"\A(?:((/|id:).*)|(rev:[0-9a-f]{9,}))\z"))
44+
if (!re.Regex.IsMatch(path, @"\A(?:((/|id:).*)|(rev:[0-9a-f]{9,}))\z"))
4545
{
46-
throw new sys.ArgumentOutOfRangeException("path");
46+
throw new sys.ArgumentOutOfRangeException("path", @"Value should match pattern '\A(?:((/|id:).*)|(rev:[0-9a-f]{9,}))\z'");
4747
}
4848

4949
this.Path = path;

0 commit comments

Comments
 (0)