@@ -22,6 +22,7 @@ import {
2222 type TelegramConfig ,
2323} from '@ai-devkit/channel-connector' ;
2424import { ui } from '../util/terminal-ui' ;
25+ import { getErrorMessage } from '../util/text' ;
2526import { createLogger , enableDebug } from '../util/debug' ;
2627
2728const debug = createLogger ( 'channel' ) ;
@@ -98,9 +99,10 @@ function setupInputHandler(
9899 try {
99100 await TtyWriter . send ( terminalLocation , msg . text ) ;
100101 debug ( `Sent message to agent terminal (length: ${ msg . text ?. length ?? 0 } )` ) ;
101- } catch ( error : any ) {
102- ui . error ( `Failed to send to agent: ${ error . message } ` ) ;
103- await telegram . sendMessage ( msg . chatId , `Failed to send to agent: ${ error . message } ` ) ;
102+ } catch ( error : unknown ) {
103+ const message = getErrorMessage ( error ) ;
104+ ui . error ( `Failed to send to agent: ${ message } ` ) ;
105+ await telegram . sendMessage ( msg . chatId , `Failed to send to agent: ${ message } ` ) ;
104106 }
105107 } ) ;
106108}
@@ -214,7 +216,7 @@ export function registerChannelCommand(program: Command): void {
214216 const me = await bot . telegram . getMe ( ) ;
215217 botUsername = me . username ;
216218 spinner . succeed ( `Connected to bot @${ botUsername } ` ) ;
217- } catch ( error : any ) {
219+ } catch ( error : unknown ) {
218220 spinner . fail ( 'Invalid bot token. Please check and try again.' ) ;
219221 return ;
220222 }
@@ -234,8 +236,8 @@ export function registerChannelCommand(program: Command): void {
234236 ui . info ( `Bot: @${ botUsername } ` ) ;
235237 ui . info ( 'Run "ai-devkit channel start --agent <name>" to start the bridge.' ) ;
236238
237- } catch ( error : any ) {
238- ui . error ( `Failed to connect channel: ${ error . message } ` ) ;
239+ } catch ( error : unknown ) {
240+ ui . error ( `Failed to connect channel: ${ getErrorMessage ( error ) } ` ) ;
239241 process . exit ( 1 ) ;
240242 }
241243 } ) ;
@@ -272,8 +274,8 @@ export function registerChannelCommand(program: Command): void {
272274 rows,
273275 } ) ;
274276
275- } catch ( error : any ) {
276- ui . error ( `Failed to list channels: ${ error . message } ` ) ;
277+ } catch ( error : unknown ) {
278+ ui . error ( `Failed to list channels: ${ getErrorMessage ( error ) } ` ) ;
277279 process . exit ( 1 ) ;
278280 }
279281 } ) ;
@@ -303,8 +305,8 @@ export function registerChannelCommand(program: Command): void {
303305 await configStore . removeChannel ( type ) ;
304306 ui . success ( `${ type } channel disconnected.` ) ;
305307
306- } catch ( error : any ) {
307- ui . error ( `Failed to disconnect channel: ${ error . message } ` ) ;
308+ } catch ( error : unknown ) {
309+ ui . error ( `Failed to disconnect channel: ${ getErrorMessage ( error ) } ` ) ;
308310 process . exit ( 1 ) ;
309311 }
310312 } ) ;
@@ -387,9 +389,10 @@ export function registerChannelCommand(program: Command): void {
387389
388390 // Keep process running
389391 await new Promise ( ( ) => { } ) ;
390- } catch ( error : any ) {
391- debug ( `Error caught: ${ error . stack ?? error . message } ` ) ;
392- ui . error ( `Failed to start channel bridge: ${ error . message } ` ) ;
392+ } catch ( error : unknown ) {
393+ const message = getErrorMessage ( error ) ;
394+ debug ( `Error caught: ${ error instanceof Error ? error . stack : message } ` ) ;
395+ ui . error ( `Failed to start channel bridge: ${ message } ` ) ;
393396 process . exit ( 1 ) ;
394397 }
395398 } ) ;
0 commit comments