Skip to content

Commit 7d137f9

Browse files
Harden Storage task snapshot access (#171)
1 parent 0f6450d commit 7d137f9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

source/Firebase/Storage/Extension.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@ public partial class StorageTaskSnapshot
1919
{
2020
public StorageTask GetTask ()
2121
{
22+
if (_Task == IntPtr.Zero)
23+
throw new InvalidOperationException ("Firebase Storage task snapshot does not contain a task.");
24+
2225
var task = Runtime.GetNSObject<StorageTask> (_Task);
23-
return task;
26+
return task ?? throw new InvalidOperationException ("Unable to resolve Firebase Storage task.");
2427
}
2528

2629
public T GetTask<T> () where T : StorageTask
2730
{
31+
if (_Task == IntPtr.Zero)
32+
throw new InvalidOperationException ("Firebase Storage task snapshot does not contain a task.");
33+
2834
var task = Runtime.GetNSObject<T> (_Task);
29-
return task;
35+
return task ?? throw new InvalidOperationException ($"Unable to resolve Firebase Storage task as {typeof (T).FullName}.");
3036
}
3137
}
3238
}

0 commit comments

Comments
 (0)