Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Remove die calls, add source description to error messages. #28

Merged
merged 1 commit into from
Nov 11, 2014

Conversation

wedi
Copy link
Contributor

@wedi wedi commented Nov 11, 2014

Hi!

This pull request replaces all calls to die() with trigger_error() in the API functions.

IMO it’s not a good idea for an API to call die() as it’s catchable only via the ugly register_shutdown_function() which one cannot remove after the GeoIP API call. This change allows devs to gracefully handle these errors (by setting set_error_handler) instead of hard breaking all functionality. Let the dev instead of the API decide whether to hard break an app/website/…, to ignore the error or to show a neat message.

Additionally I’ve added a source description in front of the error messages to easier locate error messages reported by end users.

Thanks!

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 7b6114b on wedi:remove-die into eb2085b on maxmind:master.

@oschwald
Copy link
Member

I agree with the general premise of this PR. Are you using trigger_error() instead of exceptions for PHP 4 compatibility? I think we could probably drop PHP 4 support, assuming the library still works on PHP 4.

@wedi
Copy link
Contributor Author

wedi commented Nov 11, 2014

I would have opted for using exceptions, too, if you hadn't used trigger_error() in the code already and if I hadn't had to use trigger_error() anyway: in the past users set invalid database files and I need to reliably catch the resulting notices, warnings and/or errors.

@oschwald
Copy link
Member

Yeah, that makes sense. Longer term, you might want to consider upgrading to GeoIP2. That API is much more modern.

oschwald added a commit that referenced this pull request Nov 11, 2014
Remove die calls, add source description to error messages.
@oschwald oschwald merged commit 324abc6 into maxmind:master Nov 11, 2014
@wedi
Copy link
Contributor Author

wedi commented Nov 11, 2014

As I think about it, I'd suggest to stay with trigger_error() as that's what all products using this lib are already expecting as it's already used in the code. This is legacy. Modernizing the code should probably be left to the current API instead of requiring changes in old code.

@wedi
Copy link
Contributor Author

wedi commented Nov 11, 2014

I will definitely do the switch. Thanks for merging.

@wedi wedi deleted the remove-die branch November 11, 2014 21:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants