Skip to content
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

(FM-5324) Fix TSQL error propagation #173

Merged
merged 11 commits into from Jun 8, 2016

Conversation

Iristyle
Copy link
Contributor

@Iristyle Iristyle commented Jun 8, 2016

Refactor SqlConnection / tests to simplify code.

Fix error propagation in SqlConnection

 - This method only appears in tests
 - Minor refactor to make the return value more obvious
 - This method is extraneous / confusing.  Better to refactor all code
   to execute with the providers `run` method
 - Introduce a minor refactor so that the `returns` property captures
   errors properly from TSQL executions.  Previously, if a `refresh`
   occurred against a sqlserver_tsql the output would cause a failure,
   but simply executing TSQL would not do the same.

   Follow the same model as the Puppet exec type (where much of this
   code comes from), and have `refresh` trigger the `sync` method of
   the `results` property, so that the code is now shared.
 - The command method for SqlConnection only has a single caller,
   the block form is never used and the result is not either.
   Furthermore, the caller open_and_run_command, already catches
   win32_exception, so there's more code here than necessary.
 - The existing code only has one code path, so remove the unneeded
   method.
 - Tests should be better (self) documented
 - Properly parse errors that look like:
SQL Server
error message

   instead of those that must have whitespace like:
SQL Server
 error message
 - The existing SqlConnection class has a public property
   exception_caught, which is not used.  Further, it uses this value
   to save off exceptions inside the class, rather than simply
   returning the parsed errors when open_and_run_command is executed,
   which is presently the only caller that ever looks at the
   error values.

   This provides an opportunity to simplify the code paths, and remove
   unnecessary caching of errors and the 2 unnecessary methods
   has_errors and error_message from the SqlConnection class.

   Instead, directly return a new ResultOutput instance as soon as
   SQL code is executed.

   Tests are modified accordingly.
 - Previously, there was no way of getting the log output from SQL
   Server when executing TSQL during an onlyif.  Only the status code
   was emitted, which is not helpful when trying to debug.
 - These tests were previously stubbing return values instead of
   asserting that the code was behaving properly.
@glennsarti glennsarti merged commit e55a0ca into puppetlabs:master Jun 8, 2016
@Iristyle Iristyle deleted the maint/sqlconnection-refactor branch June 10, 2016 20:37
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.

None yet

2 participants