Skip to content

Make the ParseObject construct throw more specific exceptions #56

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 3 commits into from Nov 17, 2014
Merged

Make the ParseObject construct throw more specific exceptions #56

merged 3 commits into from Nov 17, 2014

Conversation

ghost
Copy link

@ghost ghost commented Nov 11, 2014

In a scenario of a developer not utilizing ParseClient::initialize before calling another object such as new ParseUser(), the user receives a message about specifying a Parse class name or using ParseObject::create, throwing them in the wrong direction about their error. This commit adds one more line to the Exception asking them if they in fact remembered to use ParseClient::initialize before being thrown away from their obvious mistake - this should prevent questions like these or #55 from occurring.

The resulting Exception now displays as such:

[11-Nov-2014 20:19:34 Europe/Berlin] PHP Fatal error: Uncaught exception 'Exception' with message 'You must specify a Parse class name or register the appropriate subclass when creating a new Object. Use ParseObject::create to create a subclass object. Perhaps you forgot to use ParseClient::initialize before creating your Object?' in /Users/schuylerjager/Desktop/GitRepos/parse-test/parse-php-sdk/src/Parse/ParseObject.php:88
Stack trace:
0 /Users/schuylerjager/Desktop/GitRepos/parse-test/index.php(17): Parse\ParseObject->__construct()
1 {main}
thrown in /Users/schuylerjager/Desktop/GitRepos/parse-test/parse-php-sdk/src/Parse/ParseObject.php on line 88

@ghost ghost closed this Nov 11, 2014
@ghost ghost reopened this Nov 11, 2014
@ghost
Copy link
Author

ghost commented Nov 11, 2014

Forgot that GitHub includes the latest commits in a Pull Request if not merged yet. I've modified my approach to use a new Exception instead of modifying the existing one which could cause confusion as to which mistake the developer has made. Now the user will see the following only if they fail to ParseClient::initialize:

[11-Nov-2014 20:34:18 Europe/Berlin] PHP Fatal error: Uncaught exception 'Exception' with message 'You must initialize the ParseClient using ParseClient::initialize and your Parse API keys before you can begin working with Objects.' in /Users/schuylerjager/Desktop/GitRepos/parse-test/parse-php-sdk/src/Parse/ParseObject.php:83
Stack trace:
0 /Users/schuylerjager/Desktop/GitRepos/parse-test/index.php(18): Parse\ParseObject->__construct()
1 {main} thrown in /Users/schuylerjager/Desktop/GitRepos/parse-test/parse-php-sdk/src/Parse/ParseObject.php on line 83

Sorry in advance for the multiple commits.

@ghost ghost changed the title Make the ParseObject construct throw a more descriptive exception Make the ParseObject construct throw more descriptive exceptions Nov 11, 2014
@ghost ghost changed the title Make the ParseObject construct throw more descriptive exceptions Make the ParseObject construct throw more specific exceptions Nov 11, 2014
gfosco added a commit that referenced this pull request Nov 17, 2014
Make the ParseObject construct throw more specific exceptions
@gfosco gfosco merged commit 7ddeede into parse-community:master Nov 17, 2014
@gfosco
Copy link
Contributor

gfosco commented Nov 17, 2014

Thanks. 👍

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.

2 participants