Fix schema plugin unreachable except block#726
Open
odaysec wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix schema plugin unreachable except block#726odaysec wants to merge 1 commit intomicrosoft:mainfrom
odaysec wants to merge 1 commit intomicrosoft:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix is to ensure that more specific exceptions are caught before more general ones, and that there is only one handler for a given exception type in a
trystatement. In this case, we have twoexcept Exception as e:blocks; the second one (lines 332–334) is unreachable and should be removed. Additionally, the code after thereturninside the firstexcept(lines 314–330) is dead and should be restored to the normal execution path inside thetryblock instead of being inside the exception handler.The best fix that preserves intended functionality is:
except Exception as e:block at the end of thetry.exceptafter line 313) back into thetryblock, following the connection/cursor setup and any other preparatory logic (within the sametrythat begins around line 237).except Exception as e:(lines 301–312) entirely in favor of the finalexcept(lines 332–334), or equivalently, merge their logging/return behavior into a singleexceptat the end.exceptlogs the detailed error and either returns aResultWithMetadataobject (as in the first handler) or re‑raises, whichever matches the plugin’s contract; given the surrounding code, returning an errorResultWithMetadatais consistent with other plugin methods that encapsulate errors.Since we only see part of the
tryblock, the concrete change withinapplication/single_app/semantic_kernel_plugins/sql_schema_plugin.pyshould:except Exception as e:block (lines 301–312).tryblock.except Exception as e:(lines 332–334) with a handler that performs the same logging andResultWithMetadatareturn behavior as the original first handler, instead of re‑raising.