@@ -57,7 +57,7 @@ use crate::{
5757 processing:: CodeMirrorDiffable ,
5858 queue_send,
5959 webserver:: {
60- INITIAL_IDE_MESSAGE_ID , MESSAGE_ID_INCREMENT , ResultOkTypes , WebAppState ,
60+ INITIAL_IDE_MESSAGE_ID , MESSAGE_ID_INCREMENT , ResultErrTypes , ResultOkTypes , WebAppState ,
6161 filesystem_endpoint, get_test_mode,
6262 } ,
6363} ;
@@ -463,12 +463,12 @@ async fn processing_task(
463463 for err in err_vec {
464464 // Report errors locally and to the CodeChat
465465 // Editor.
466- let msg = format! ( "Watcher error: { err}" ) ;
467- error!( "{msg }" ) ;
466+ let err = ResultErrTypes :: FileWatchingError ( err. to_string ( ) ) ;
467+ error!( "{err:? }" ) ;
468468 // Send using an ID which indicates this isn't a
469469 // response to a message received from the
470470 // client.
471- send_response( & from_ide_tx, RESERVED_MESSAGE_ID , Err ( msg ) ) . await ;
471+ send_response( & from_ide_tx, RESERVED_MESSAGE_ID , Err ( err ) ) . await ;
472472 }
473473 }
474474
@@ -556,10 +556,7 @@ async fn processing_task(
556556 // file. If `canonicalize` fails, then the files
557557 // don't match.
558558 if Some ( Path :: new( & update_message_contents. file_path) . to_path_buf( ) ) != current_filepath {
559- break ' process Err ( format!(
560- "Update for file '{}' doesn't match current file '{current_filepath:?}'." ,
561- update_message_contents. file_path
562- ) ) ;
559+ break ' process Err ( ResultErrTypes :: WrongFileUpdate ( update_message_contents. file_path, current_filepath. clone( ) ) ) ;
563560 }
564561 // With code or a path, there's nothing to save.
565562 let codechat_for_web = match update_message_contents. contents {
@@ -578,26 +575,14 @@ async fn processing_task(
578575 // it, in order to avoid a watch notification
579576 // from this write.
580577 if let Err ( err) = debounced_watcher. unwatch( cfp) {
581- let msg = format!(
582- "Unable to unwatch file '{}': {err}." ,
583- cfp. to_string_lossy( )
584- ) ;
585- break ' process Err ( msg) ;
578+ break ' process Err ( ResultErrTypes :: FileUnwatchError ( cfp. to_path_buf( ) , err. to_string( ) ) ) ;
586579 }
587580 // Save this string to a file.
588581 if let Err ( err) = fs:: write( cfp. as_path( ) , plain. doc) . await {
589- let msg = format!(
590- "Unable to save file '{}': {err}." ,
591- cfp. to_string_lossy( )
592- ) ;
593- break ' process Err ( msg) ;
582+ break ' process Err ( ResultErrTypes :: SaveFileError ( cfp. to_path_buf( ) , err. to_string( ) ) ) ;
594583 }
595584 if let Err ( err) = debounced_watcher. watch( cfp, RecursiveMode :: NonRecursive ) {
596- let msg = format!(
597- "Unable to watch file '{}': {err}." ,
598- cfp. to_string_lossy( )
599- ) ;
600- break ' process Err ( msg) ;
585+ break ' process Err ( ResultErrTypes :: FileWatchError ( cfp. to_path_buf( ) , err. to_string( ) ) ) ;
601586 }
602587 Ok ( ResultOkTypes :: Void )
603588 } ;
@@ -611,19 +596,14 @@ async fn processing_task(
611596 if let Some ( cfp) = & current_filepath
612597 && let Err ( err) = debounced_watcher. unwatch( cfp)
613598 {
614- break ' err_exit Err ( format!(
615- "Unable to unwatch file '{}': {err}." ,
616- cfp. to_string_lossy( )
617- ) ) ;
599+ break ' err_exit Err ( ResultErrTypes :: FileUnwatchError ( cfp. to_path_buf( ) , err. to_string( ) ) ) ;
618600 }
619601 // Update to the new path.
620602 current_filepath = Some ( file_path. to_path_buf( ) ) ;
621603
622604 // Watch the new file.
623- if let Err ( err) = debounced_watcher. watch( file_path, RecursiveMode :: NonRecursive ) {
624- break ' err_exit Err ( format!(
625- "Unable to watch file '{file_path_str}': {err}." ,
626- ) ) ;
605+ if let Err ( err) = debounced_watcher. watch( & file_path, RecursiveMode :: NonRecursive ) {
606+ break ' err_exit Err ( ResultErrTypes :: FileWatchError ( file_path. to_path_buf( ) , err. to_string( ) ) ) ;
627607 }
628608 // Indicate there was no error in the `Result`
629609 // message.
@@ -656,9 +636,9 @@ async fn processing_task(
656636 EditorMessageContents :: OpenUrl ( _) |
657637 EditorMessageContents :: ClientHtml ( _) |
658638 EditorMessageContents :: RequestClose => {
659- let msg = format! ( "Client sent unsupported message type {m:?}" ) ;
660- error!( "{msg }" ) ;
661- send_response( & from_ide_tx, m. id, Err ( msg ) ) . await ;
639+ let err = ResultErrTypes :: ClientIllegalMessage ;
640+ error!( "{err:? }" ) ;
641+ send_response( & from_ide_tx, m. id, Err ( err ) ) . await ;
662642 }
663643 }
664644 }
@@ -727,7 +707,6 @@ mod tests {
727707 dev:: { Service , ServiceResponse } ,
728708 test,
729709 } ;
730- use assertables:: assert_starts_with;
731710 use dunce:: simplified;
732711 use path_slash:: PathExt ;
733712 use pretty_assertions:: assert_eq;
@@ -745,8 +724,8 @@ mod tests {
745724 webserver:: {
746725 EditorMessage , EditorMessageContents , INITIAL_CLIENT_MESSAGE_ID ,
747726 INITIAL_IDE_MESSAGE_ID , INITIAL_MESSAGE_ID , IdeType , MESSAGE_ID_INCREMENT ,
748- ResultOkTypes , UpdateMessageContents , WebAppState , WebsocketQueues , configure_app ,
749- drop_leading_slash, make_app_data, send_response, set_root_path,
727+ ResultErrTypes , ResultOkTypes , UpdateMessageContents , WebAppState , WebsocketQueues ,
728+ configure_app , drop_leading_slash, make_app_data, send_response, set_root_path,
750729 } ,
751730 } ;
752731
@@ -963,7 +942,7 @@ mod tests {
963942 . unwrap ( ) ;
964943 let ( id_rx, msg_rx) = get_message_as ! ( to_client_rx, EditorMessageContents :: Result ) ;
965944 assert_eq ! ( id, id_rx) ;
966- assert_starts_with ! ( cast!( & msg_rx, Err ) , "Client must not send this message." ) ;
945+ matches ! ( cast!( & msg_rx, Err ) , ResultErrTypes :: ClientIllegalMessage ) ;
967946 }
968947
969948 // 5. Send an update message with no path.
@@ -993,10 +972,7 @@ mod tests {
993972 // Check that it produces an error.
994973 let ( id, err_msg) = get_message_as ! ( to_client_rx, EditorMessageContents :: Result ) ;
995974 assert_eq ! ( id, INITIAL_CLIENT_MESSAGE_ID + 4.0 * MESSAGE_ID_INCREMENT ) ;
996- assert_starts_with ! (
997- cast!( err_msg, Err ) ,
998- "Update for file '' doesn't match current file"
999- ) ;
975+ cast ! ( cast!( err_msg, Err ) , ResultErrTypes :: WrongFileUpdate , _a, _b) ;
1000976
1001977 // 6. Send an update message with unknown source language.
1002978 //
@@ -1023,13 +999,12 @@ mod tests {
1023999 . unwrap ( ) ;
10241000
10251001 // Check that it produces an error.
1002+ let ( msg_id, msg) = get_message_as ! ( to_client_rx, EditorMessageContents :: Result ) ;
10261003 assert_eq ! (
1027- get_message_as!( to_client_rx, EditorMessageContents :: Result ) ,
1028- (
1029- INITIAL_CLIENT_MESSAGE_ID + 5.0 * MESSAGE_ID_INCREMENT ,
1030- Err ( "Unable to translate to source: Invalid mode" . to_string( ) )
1031- )
1004+ msg_id,
1005+ INITIAL_CLIENT_MESSAGE_ID + 5.0 * MESSAGE_ID_INCREMENT
10321006 ) ;
1007+ cast ! ( cast!( msg, Err ) , ResultErrTypes :: CannotTranslateCodeChat ) ;
10331008
10341009 // 7. Send a valid message.
10351010 //
0 commit comments