@@ -61,56 +61,81 @@ export class AutoDebugCommands implements vscode.Disposable {
6161 }
6262
6363 /**
64- * Fix with Amazon Q - fixes only the specific issues the user selected
64+ * Generic error handling wrapper for command execution
6565 */
66- private async fixWithAmazonQ ( range ?: vscode . Range , diagnostics ?: vscode . Diagnostic [ ] ) : Promise < void > {
66+ private async executeWithErrorHandling < T > (
67+ action : ( ) => Promise < T > ,
68+ errorMessage : string ,
69+ logContext : string
70+ ) : Promise < T | void > {
6771 try {
68- const editor = vscode . window . activeTextEditor
69- if ( ! editor ) {
70- return
71- }
72-
73- // Controller handles panel focusing and message sending
74- await this . controller . fixSpecificProblems ( range , diagnostics )
72+ return await action ( )
7573 } catch ( error ) {
76- this . logger . error ( ' AutoDebugCommands: Error in Fix with Amazon Q : %s' , error )
74+ this . logger . error ( ` AutoDebugCommands: Error in ${ logContext } : %s` , error )
7775 void messages . showMessage ( 'error' , 'Amazon Q was not able to fix or explain the problem. Try again shortly' )
7876 }
7977 }
8078
79+ /**
80+ * Check if there's an active editor and log warning if not
81+ */
82+ private checkActiveEditor ( ) : vscode . TextEditor | undefined {
83+ const editor = vscode . window . activeTextEditor
84+ if ( ! editor ) {
85+ this . logger . warn ( 'AutoDebugCommands: No active editor found' )
86+ }
87+ return editor
88+ }
89+
90+ /**
91+ * Fix with Amazon Q - fixes only the specific issues the user selected
92+ */
93+ private async fixWithAmazonQ ( range ?: vscode . Range , diagnostics ?: vscode . Diagnostic [ ] ) : Promise < void > {
94+ await this . executeWithErrorHandling (
95+ async ( ) => {
96+ const editor = this . checkActiveEditor ( )
97+ if ( ! editor ) {
98+ return
99+ }
100+ await this . controller . fixSpecificProblems ( range , diagnostics )
101+ } ,
102+ 'Fix with Amazon Q' ,
103+ 'fixWithAmazonQ'
104+ )
105+ }
106+
81107 /**
82108 * Fix All with Amazon Q - processes all errors in the current file
83109 */
84110 private async fixAllWithAmazonQ ( ) : Promise < void > {
85- try {
86- const editor = vscode . window . activeTextEditor
87- if ( ! editor ) {
88- return
89- }
90-
91- await this . controller . fixAllProblemsInFile ( 10 ) // 10 errors per batch
92- } catch ( error ) {
93- this . logger . error ( 'AutoDebugCommands: Error in Fix All with Amazon Q: %s' , error )
94- void messages . showMessage ( 'error' , 'Amazon Q was not able to fix or explain the problem. Try again shortly' )
95- }
111+ await this . executeWithErrorHandling (
112+ async ( ) => {
113+ const editor = this . checkActiveEditor ( )
114+ if ( ! editor ) {
115+ return
116+ }
117+ await this . controller . fixAllProblemsInFile ( 10 ) // 10 errors per batch
118+ } ,
119+ ' Fix All with Amazon Q' ,
120+ 'fixAllWithAmazonQ'
121+ )
96122 }
97123
98124 /**
99125 * Explains the problem using Amazon Q
100126 */
101127 private async explainProblem ( range ?: vscode . Range , diagnostics ?: vscode . Diagnostic [ ] ) : Promise < void > {
102- try {
103- const editor = vscode . window . activeTextEditor
104- if ( ! editor ) {
105- this . logger . warn ( 'AutoDebugCommands: No active editor for explainProblem' )
106- return
107- }
108-
109- await this . controller . explainProblems ( range , diagnostics )
110- } catch ( error ) {
111- this . logger . error ( 'AutoDebugCommands: Error explaining problem: %s' , error )
112- void messages . showMessage ( 'error' , 'Amazon Q was not able to fix or explain the problem. Try again shortly' )
113- }
128+ await this . executeWithErrorHandling (
129+ async ( ) => {
130+ const editor = this . checkActiveEditor ( )
131+ if ( ! editor ) {
132+ return
133+ }
134+ await this . controller . explainProblems ( range , diagnostics )
135+ } ,
136+ 'Explain Problem' ,
137+ 'explainProblem'
138+ )
114139 }
115140
116141 /**
0 commit comments