Skip to content

Use errors instead of exceptions when creating a PFFile. #345

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

Merged
merged 1 commit into from
Sep 29, 2015

Conversation

richardjrossiii
Copy link
Contributor

Switching to errors provides a more consistent interface, as we should never use exceptions in objective-c except for unrecoverable errors.

Fixes #338.

if (![fileManager fileExistsAtPath:path isDirectory:&directory] || directory) {
NSString *message = [NSString stringWithFormat:@"Failed to create PFFile at path '%@': "
"file does not exist.", path];
*error = [NSError errorWithDomain:PFParseErrorDomain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 things here:

  • let's use PFErrorUtilities to create an error, since it enforces PFParseErrorDomain, as well as logs to console by default.
  • We should fine a code that fits this best from existing error codes, or avoid using PFParseErrorDomain, since we have a guarantee that we never use anything other than errors defined in PFConstants (PFErrorCode) enum.

@nlutsenko
Copy link
Contributor

Looks great, minus usage of errors.
Also, I guess it's worthwile adding a test for nil NSData?

@"PFFile cannot be larger than %llu bytes", PFFileMaxFileSize);
if (!data) {
NSString *message = @"Cannot create a PFFile with nil data.";
*error = [NSError errorWithDomain:NSPOSIXErrorDomain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use NSCocoaErrorDomain with maybe NSFileNoSuchFileError?

@nlutsenko
Copy link
Contributor

Be aware - Travis failed miserably on this one.

Switching to errors provides a more consistent interface, as we should never use exceptions in objective-c except for unrecoverable errors.

Fixes #338.
@nlutsenko
Copy link
Contributor

Ship it!

richardjrossiii added a commit that referenced this pull request Sep 29, 2015
Use errors instead of exceptions when creating a PFFile.
@richardjrossiii richardjrossiii merged commit a801309 into master Sep 29, 2015
@richardjrossiii richardjrossiii deleted the richardross.file.error branch September 29, 2015 06:04
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

Successfully merging this pull request may close these issues.

3 participants