Skip to content

Move error_number and sql_state into Mysql2::Error initializer #545

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
Sep 10, 2015

Conversation

sodabrew
Copy link
Collaborator

An alternative to #544, make all of the needed parameters into the initialize method.

@simi
Copy link
Contributor

simi commented Sep 14, 2014

Is there any situation when user should raise Mysql2:Error manually?

@sodabrew
Copy link
Collaborator Author

I don't think so. But it does change the interface away from StandardError, which only takes one argument. Alternatively, add a second constructor, e.g. new_with_sql_state.

Edit: server_version is already an extra argument beyond StandardError.

@simi
Copy link
Contributor

simi commented Sep 14, 2014

Current implementation differs from StandardError constructor also.
http://www.ruby-doc.org/core-2.1.2/Exception.html#method-c-new (1 optional - msg)
def initialize(msg, server_version=nil) (1 mandatory, 1 optional)

@sodabrew
Copy link
Collaborator Author

@seuros I don't think changing the initialize method is a problematic change, because the arguments are very new. server_version was added in 271ea5e in January 2014 for version 0.3.15.

That said, I further modified the PR to move server_version and the other args into new_with_args. Let me know what you think of this approach.

Ideally, this is where we would use a separate exception class. For 0.4 perhaps.

@simi
Copy link
Contributor

simi commented Sep 14, 2014

I'm still not getting the idea behind new_with_args. Compatibility trade-off?

@sodabrew
Copy link
Collaborator Author

Sort of a thought experiment, since the extra args are only used by one caller in client.c, and don't really fit a getter/setter pattern because the args are only added at initialization.=

@seuros
Copy link
Contributor

seuros commented Sep 14, 2014

I will have to check tomorrow my logs, I think it was some gem that raised this error when a deadlock is detected.
Fell free to merge this PR , then yours. We can always return to this change in case we break too many implementation?

We should also think about a major version bump, so we can remove all the legacy code. wdyt ?

@sodabrew
Copy link
Collaborator Author

Yes, I'm planning for 0.4 "soon", after a 0.3.17 bugfix release.

@sodabrew sodabrew force-pushed the initialize_more_errors branch from 5a9d07b to 576d6df Compare September 14, 2014 21:29
@sodabrew sodabrew added this to the 0.4.0 milestone Sep 20, 2014
@sodabrew sodabrew force-pushed the initialize_more_errors branch from 576d6df to 66107d0 Compare June 12, 2015 05:54
@sodabrew sodabrew modified the milestones: 0.4.0, 0.4.1 Aug 5, 2015
@sodabrew sodabrew force-pushed the initialize_more_errors branch from 66107d0 to 98710ac Compare September 1, 2015 14:56
@sodabrew sodabrew force-pushed the initialize_more_errors branch 3 times, most recently from 7a5065d to 5a8bd66 Compare September 10, 2015 01:26
@sodabrew
Copy link
Collaborator Author

I was also hoping this would fix #641 but it's still busted with:

  1) Mysql2::Error encoding returns error messages and sql state in Encoding.default_internal if set

     Failure/Error: client.query(valid_utf8)
     LoadError:
       dlopen(e, 9): image not found - e
     # ./lib/mysql2/error.rb:27:in `encode'
     # ./lib/mysql2/error.rb:27:in `new_with_args'
     # ./lib/mysql2/client.rb:87:in `_query'
     # ./lib/mysql2/client.rb:87:in `block in query'
     # ./lib/mysql2/client.rb:86:in `handle_interrupt'
     # ./lib/mysql2/client.rb:86:in `query'
     # ./spec/mysql2/error_spec.rb:31:in `block (3 levels) in <top (required)>'
     # ./spec/mysql2/error_spec.rb:76:in `block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:19:in `with_internal_encoding'
     # ./spec/mysql2/error_spec.rb:75:in `block (3 levels) in <top (required)>'

@sodabrew sodabrew force-pushed the initialize_more_errors branch from 5a8bd66 to abd06c5 Compare September 10, 2015 01:50
sodabrew added a commit that referenced this pull request Sep 10, 2015
Move error_number and sql_state into Mysql2::Error initializer
@sodabrew sodabrew merged commit 5c5543f into brianmario:master Sep 10, 2015
@sodabrew sodabrew deleted the initialize_more_errors branch September 10, 2015 13:40
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