Skip to content

Improve error messages when creating an invalid PFFile. #338

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

Closed
richardjrossiii opened this issue Sep 27, 2015 · 3 comments
Closed

Improve error messages when creating an invalid PFFile. #338

richardjrossiii opened this issue Sep 27, 2015 · 3 comments
Assignees

Comments

@richardjrossiii
Copy link
Contributor

Currently, if you attempt to create a PFFile with a nil NSData parameter, you get a strange 'file not found' error when attempting to save it to Parse.

Let's make this either

  • Throw an exception
  • Make the PFFile constructor return nil, when invalid data is passed in.

Somewhat relates to #6.

@nlutsenko
Copy link
Contributor

Sounds great! Let's do it!
We have this method:

+ (instancetype)fileWithName:(PF_NULLABLE NSString *)name
                        data:(NSData *)data
                 contentType:(PF_NULLABLE NSString *)contentType
                       error:(NSError **)error;

Which returns nil and if there was an error - it will be populated.

What do you think if we take this approach:

  • Check for nil on NSData (it's ok if it's empty probably, not ok if it's nil)
  • Add more methods that accept pointer-to-a-pointer-to-an-error (nice name 😁)
  • Mark methods without an error: parameter as unavailable in Swift, so whoever uses Swift gets throws :)

@nlutsenko
Copy link
Contributor

This is probably an example of the method signature that we are aiming for in Swift:
public convenience init(name: String?, data: NSData, contentType: String?) throws
Which is a result of this in ObjC:

+ (PF_NULLABLE instancetype)fileWithName:(PF_NULLABLE NSString *)name
                                    data:(NSData *)data
                             contentType:(PF_NULLABLE NSString *)contentType PF_SWIFT_UNAVAILABLE;

+ (PF_NULLABLE instancetype)fileWithName:(PF_NULLABLE NSString *)name
                                    data:(NSData *)data
                             contentType:(PF_NULLABLE NSString *)contentType
                                   error:(NSError **)error;

richardjrossiii added a commit that referenced this issue Sep 28, 2015
Switching to errors provides a more consistent interface, as we should never use exceptions in objective-c except for unrecoverable errors.

Fixes #338.
richardjrossiii added a commit that referenced this issue Sep 28, 2015
Switching to errors provides a more consistent interface, as we should never use exceptions in objective-c except for unrecoverable errors.

Fixes #338.
richardjrossiii added a commit that referenced this issue Sep 29, 2015
Switching to errors provides a more consistent interface, as we should never use exceptions in objective-c except for unrecoverable errors.

Fixes #338.
@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
@parse-github-assistant
Copy link

The label type:feature cannot be used in combination with type:improvement.

@parse-github-assistant parse-github-assistant bot removed the type:feature New feature or improvement of existing feature label Dec 6, 2021
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