Fix schema plugin unreachable except block#726
Fix schema plugin unreachable except block#726odaysec wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
Hey @odaysec , thanks for the contribution. Can you please retarget this PR to branch off On the code change: I’m good with consolidating exception handling for better error collection, but the current return path includes I hope you follow-up with a new PR! It's great to have you contributing! |
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.