Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# SDK: How to determine if GetObjectAsync succeeded? #261

Closed
petertiedemann opened this issue Dec 14, 2018 · 7 comments
Closed

C# SDK: How to determine if GetObjectAsync succeeded? #261

petertiedemann opened this issue Dec 14, 2018 · 7 comments
Assignees

Comments

@petertiedemann
Copy link

When accessing an object with a key that does not exist, the stream provided by GetObjectAsync contains an XML error and does not throw and error when read, How should a caller avoid returning this XML error string in place of an actual string? I realize it is possible to call StatObjectAsync first, but that raises concerns about what happens if stat is called first, then before getobject a remove call is made.

Expected Behavior

I would expect an exception from GetObjectAsync if the object could not be retrieved.

Current Behavior

The stream contains an XML string:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Resource>/storagetest.f7f3da7a3a0b4ff299794b47161dccf6/Key Not Found</Resource><RequestId>15704FE60F942D64</RequestId><HostId>3L137</HostId></Error>

Possible Solution

  • Provide a separate callback for the missing object scenario
  • Provide a null stream
  • Throw an exception

Steps to Reproduce (for bugs)

Call GetObjectAsync and provide a non-existing object key.

Context

I am concerned about concurrency problems with remove operations.

Your Environment

  • Version used (minio version): 2018-12-13T02:04:19Z
  • Environment name and version (e.g. nginx 1.9.1): n/a
  • Server type and version: n/a
  • Operating System and version (uname -a): Windows 10
  • Link to your project: n/a
@petertiedemann
Copy link
Author

Looking at the other SDKs, i see its the same in Java, but in Go statObject is not suggested, so i assume the returned error would indicate that the object was not found?

@poornas
Copy link
Contributor

poornas commented Dec 14, 2018

@petertiedemann, minio-dotnet does a StatObject internally - I see a ObjectNotFoundException when GetObjectAsync is attempted on a non-existent object

 await minio.GetObjectAsync("tbucket", objectName, 
 (stream) =>
 {
      // Uncommment to print the file on output console
      // stream.CopyTo(Console.OpenStandardOutput());
 });

Cases/GetBucketNotification.cs(36,30): warning CS0168: The variable 'e' is declared but never used [/home/kris/code/minio-dotnet/Minio.Examples/Minio.Examples.csproj]
Running example for API: GetObjectAsync
[Bucket]  Exception: minio-dotnet-example-shzw2: Not found.: Minio.Exceptions.ObjectNotFoundException: Minio API responded with message=Not found.
   at Minio.MinioClient.ParseError(IRestResponse response) in /home/kris/code/minio-dotnet/Minio/MinioClient.cs:line 447
   at Minio.MinioClient.<>c.<.ctor>b__77_0(IRestResponse response) in /home/kris/code/minio-dotnet/Minio/MinioClient.cs:line 71
   at Minio.MinioClient.HandleIfErrorResponse(IRestResponse response, IEnumerable`1 handlers, DateTime startTime) in /home/kris/code/minio-dotnet/Minio/MinioClient.cs:line 503
   at Minio.MinioClient.ExecuteTaskAsync(IEnumerable`1 errorHandlers, IRestRequest request, CancellationToken cancellationToken) in /home/kris/code/minio-dotnet/Minio/MinioClient.cs:line 350
   at Minio.MinioClient.GetObjectAsync(String bucketName, String objectName, Action`1 cb, ServerSideEncryption sse, CancellationToken cancellationToken) in /home/kris/code/minio-dotnet/Minio/ApiEndpoints/ObjectOperations.cs:line 63
   at Minio.Examples.Cases.GetObject.Run(MinioClient minio, String bucketName, String objectName, String fileName) in /home/kris/code/minio-dotnet/Minio.Examples/Cases/GetObject.cs:line 34

@poornas
Copy link
Contributor

poornas commented Dec 14, 2018

ok, I see a bug in this GetObjectAsync api call where we are not doing a stat prior to fetching - will fix it.

 public async Task GetObjectAsync(string bucketName, string objectName, long offset, long length, Action<Stream> cb, ServerSideEncryption sse = null,CancellationToken cancellationToken = default(CancellationToken))

The other API call should work -

 public async Task GetObjectAsync(string bucketName, string objectName, string fileName,ServerSideEncryption sse = null, CancellationToken cancellationToken = default(CancellationToken))

@petertiedemann
Copy link
Author

@poornas Thanks for the super prompt responses, and especially the follow-up answer because i thought i had gone crazy because suddenly i was getting the exception (because i was trying a different overload i guess :)

Btw, the overload with ServerSideEncryption is not present in the nuget i am using it seems? ( i am using Minio 2.0.6 on .net standard 2.0 )

@poornas
Copy link
Contributor

poornas commented Dec 14, 2018

@petertiedemann, the serverside encryption feature is still in review #259, after merging that to master we would make a release

@petertiedemann
Copy link
Author

Ah okay, thanks. Just got worried if I was on the wrong version. Minio is looking really good so far.

@nitisht nitisht transferred this issue from minio/minio Dec 18, 2018
@nitisht
Copy link
Contributor

nitisht commented Dec 18, 2018

fixed by #260

@nitisht nitisht closed this as completed Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants