@@ -16,14 +16,13 @@ use std::{
1616} ;
1717use thiserror:: Error ;
1818use tmc_langs:: {
19- file_util,
19+ Compression , Credentials , DownloadOrUpdateCourseExercisesResult , LangsError , Language ,
20+ PrepareSubmission , TmcConfig , file_util,
2021 tmc:: {
22+ TestMyCodeClient , TestMyCodeClientError ,
2123 request:: FeedbackAnswer ,
2224 response:: { NewSubmission , SubmissionFinished } ,
23- TestMyCodeClient , TestMyCodeClientError ,
2425 } ,
25- Compression , Credentials , DownloadOrUpdateCourseExercisesResult , LangsError , Language ,
26- PrepareSubmission , TmcConfig ,
2726} ;
2827
2928#[ derive( Debug , Error ) ]
@@ -82,12 +81,6 @@ pub fn init_logging(mut cx: FunctionContext) -> JsResult<JsNull> {
8281 Ok ( cx. null ( ) )
8382}
8483
85- pub fn set_env ( mut cx : FunctionContext ) -> JsResult < JsNull > {
86- parse_args ! ( cx, key: String , val: String ) ;
87- env:: set_var ( key, val) ;
88- Ok ( cx. null ( ) )
89- }
90-
9184fn checkstyle ( mut cx : FunctionContext ) -> JsResult < JsValue > {
9285 parse_args ! ( cx, exercise_path: PathBuf , locale: String ) ;
9386 lock ! ( cx, exercise_path) ;
@@ -304,7 +297,9 @@ fn download_model_solution(mut cx: FunctionContext) -> JsResult<JsValue> {
304297 ) ;
305298
306299 let res = with_client ( client_name, client_version, |client| {
307- Ok ( client. download_model_solution ( exercise_id, & target) ?)
300+ Ok ( client
301+ . download_model_solution ( exercise_id, & target)
302+ . map_err ( Box :: new) ?)
308303 } ) ;
309304 convert_res ( & mut cx, res)
310305}
@@ -398,7 +393,7 @@ fn get_course_details(mut cx: FunctionContext) -> JsResult<JsValue> {
398393 ) ;
399394
400395 let res = with_client ( client_name, client_version, |client| {
401- Ok ( client. get_course_details ( course_id) ?)
396+ Ok ( client. get_course_details ( course_id) . map_err ( Box :: new ) ?)
402397 } ) ;
403398 convert_res ( & mut cx, res)
404399}
@@ -412,7 +407,7 @@ fn get_course_exercises(mut cx: FunctionContext) -> JsResult<JsValue> {
412407 ) ;
413408
414409 let res = with_client ( client_name, client_version, |client| {
415- Ok ( client. get_course_exercises ( course_id) ?)
410+ Ok ( client. get_course_exercises ( course_id) . map_err ( Box :: new ) ?)
416411 } ) ;
417412 convert_res ( & mut cx, res)
418413}
@@ -426,7 +421,7 @@ fn get_course_settings(mut cx: FunctionContext) -> JsResult<JsValue> {
426421 ) ;
427422
428423 let res = with_client ( client_name, client_version, |client| {
429- Ok ( client. get_course ( course_id) ?)
424+ Ok ( client. get_course ( course_id) . map_err ( Box :: new ) ?)
430425 } ) ;
431426 convert_res ( & mut cx, res)
432427}
@@ -440,7 +435,7 @@ fn get_courses(mut cx: FunctionContext) -> JsResult<JsValue> {
440435 ) ;
441436
442437 let res = with_client ( client_name, client_version, |client| {
443- Ok ( client. list_courses ( & organization) ?)
438+ Ok ( client. list_courses ( & organization) . map_err ( Box :: new ) ?)
444439 } ) ;
445440 convert_res ( & mut cx, res)
446441}
@@ -454,7 +449,7 @@ fn get_exercise_details(mut cx: FunctionContext) -> JsResult<JsValue> {
454449 ) ;
455450
456451 let res = with_client ( client_name, client_version, |client| {
457- Ok ( client. get_exercise_details ( exercise_id) ?)
452+ Ok ( client. get_exercise_details ( exercise_id) . map_err ( Box :: new ) ?)
458453 } ) ;
459454 convert_res ( & mut cx, res)
460455}
@@ -468,7 +463,9 @@ fn get_exercise_submissions(mut cx: FunctionContext) -> JsResult<JsValue> {
468463 ) ;
469464
470465 let res = with_client ( client_name, client_version, |client| {
471- Ok ( client. get_exercise_submissions_for_current_user ( exercise_id) ?)
466+ Ok ( client
467+ . get_exercise_submissions_for_current_user ( exercise_id)
468+ . map_err ( Box :: new) ?)
472469 } ) ;
473470 convert_res ( & mut cx, res)
474471}
@@ -484,7 +481,9 @@ fn get_exercise_updates(mut cx: FunctionContext) -> JsResult<JsValue> {
484481
485482 let map = exercise. into_iter ( ) . collect ( ) ;
486483 let res = with_client ( client_name, client_version, |client| {
487- Ok ( client. get_exercise_updates ( course_id, map) ?)
484+ Ok ( client
485+ . get_exercise_updates ( course_id, map)
486+ . map_err ( Box :: new) ?)
488487 } ) ;
489488 convert_res ( & mut cx, res)
490489}
@@ -498,7 +497,7 @@ fn get_organization(mut cx: FunctionContext) -> JsResult<JsValue> {
498497 ) ;
499498
500499 let res = with_client ( client_name, client_version, |client| {
501- Ok ( client. get_organization ( & organization) ?)
500+ Ok ( client. get_organization ( & organization) . map_err ( Box :: new ) ?)
502501 } ) ;
503502 convert_res ( & mut cx, res)
504503}
@@ -507,7 +506,7 @@ fn get_organizations(mut cx: FunctionContext) -> JsResult<JsValue> {
507506 parse_args ! ( cx, client_name: String , client_version: String ) ;
508507
509508 let res = with_client ( client_name, client_version, |client| {
510- Ok ( client. get_organizations ( ) ?)
509+ Ok ( client. get_organizations ( ) . map_err ( Box :: new ) ?)
511510 } ) ;
512511 convert_res ( & mut cx, res)
513512}
@@ -521,7 +520,7 @@ fn get_unread_reviews(mut cx: FunctionContext) -> JsResult<JsValue> {
521520 ) ;
522521
523522 let res = with_client ( client_name, client_version, |client| {
524- Ok ( client. get_unread_reviews ( course_id) ?)
523+ Ok ( client. get_unread_reviews ( course_id) . map_err ( Box :: new ) ?)
525524 } ) ;
526525 convert_res ( & mut cx, res)
527526}
@@ -600,7 +599,9 @@ fn mark_review_as_read(mut cx: FunctionContext) -> JsResult<JsValue> {
600599 ) ;
601600
602601 let res = with_client ( client_name, client_version, |client| {
603- Ok ( client. mark_review_as_read ( course_id, review_id) ?)
602+ Ok ( client
603+ . mark_review_as_read ( course_id, review_id)
604+ . map_err ( Box :: new) ?)
604605 } ) ;
605606 convert_res ( & mut cx, res)
606607}
@@ -619,7 +620,9 @@ fn paste(mut cx: FunctionContext) -> JsResult<JsValue> {
619620
620621 let locale = locale. map ( |l| Language :: from_639_3 ( & l) . expect ( "Invalid locale" ) ) ;
621622 let res = with_client ( client_name, client_version, |client| {
622- Ok ( client. paste ( exercise_id, & submission_path, paste_message, locale) ?)
623+ Ok ( client
624+ . paste ( exercise_id, & submission_path, paste_message, locale)
625+ . map_err ( Box :: new) ?)
623626 } ) ;
624627 convert_res ( & mut cx, res)
625628}
@@ -638,12 +641,14 @@ fn request_code_review(mut cx: FunctionContext) -> JsResult<JsValue> {
638641
639642 let locale = Language :: from_639_3 ( & locale) . expect ( "Invalid locale" ) ;
640643 let res = with_client ( client_name, client_version, |client| {
641- Ok ( client. request_code_review (
642- exercise_id,
643- & submission_path,
644- message_for_reviewer,
645- Some ( locale) ,
646- ) ?)
644+ Ok ( client
645+ . request_code_review (
646+ exercise_id,
647+ & submission_path,
648+ message_for_reviewer,
649+ Some ( locale) ,
650+ )
651+ . map_err ( Box :: new) ?)
647652 } ) ;
648653 convert_res ( & mut cx, res)
649654}
@@ -661,7 +666,9 @@ fn reset_exercise(mut cx: FunctionContext) -> JsResult<JsValue> {
661666
662667 let res = with_client ( client_name, client_version, |client| {
663668 if save_old_state {
664- client. submit ( exercise_id, & exercise_path, None ) ?;
669+ client
670+ . submit ( exercise_id, & exercise_path, None )
671+ . map_err ( Box :: new) ?;
665672 }
666673 tmc_langs:: reset ( client, exercise_id, & exercise_path)
667674 } ) ;
@@ -685,7 +692,9 @@ fn send_feedback(mut cx: FunctionContext) -> JsResult<JsValue> {
685692 } )
686693 . collect ( ) ;
687694 let res = with_client ( client_name, client_version, |client| {
688- Ok ( client. send_feedback ( submission_id, feedback) ?)
695+ Ok ( client
696+ . send_feedback ( submission_id, feedback)
697+ . map_err ( Box :: new) ?)
689698 } ) ;
690699 convert_res ( & mut cx, res)
691700}
@@ -708,15 +717,19 @@ fn submit(mut cx: FunctionContext) -> JsResult<JsValue> {
708717
709718 let locale = locale. map ( |l| Language :: from_639_3 ( & l) . expect ( "Invalid locale" ) ) ;
710719 let temp = with_client ( client_name, client_version, |client| {
711- let new_submission = client. submit ( exercise_id, & submission_path, locale) ?;
720+ let new_submission = client
721+ . submit ( exercise_id, & submission_path, locale)
722+ . map_err ( Box :: new) ?;
712723 if dont_block {
713724 Ok ( Temp :: NewSubmission ( new_submission) )
714725 } else {
715726 let submission_url = new_submission
716727 . submission_url
717728 . parse ( )
718729 . expect ( "Failed to parse submission URL" ) ;
719- let finished = client. wait_for_submission_at ( submission_url) ?;
730+ let finished = client
731+ . wait_for_submission_at ( submission_url)
732+ . map_err ( Box :: new) ?;
720733 Ok ( Temp :: Finished ( Box :: new ( finished) ) )
721734 }
722735 } )
@@ -747,7 +760,9 @@ fn wait_for_submission(mut cx: FunctionContext) -> JsResult<JsValue> {
747760 ) ;
748761
749762 let res = with_client ( client_name, client_version, |client| {
750- Ok ( client. wait_for_submission ( submission_id) ?)
763+ Ok ( client
764+ . wait_for_submission ( submission_id)
765+ . map_err ( Box :: new) ?)
751766 } ) ;
752767 convert_res ( & mut cx, res)
753768}
@@ -826,7 +841,6 @@ fn unset_setting(mut cx: FunctionContext) -> JsResult<JsValue> {
826841#[ neon:: main]
827842fn main ( mut cx : ModuleContext ) -> NeonResult < ( ) > {
828843 cx. export_function ( "initLogging" , init_logging) ?;
829- cx. export_function ( "setEnv" , set_env) ?;
830844
831845 cx. export_function ( "checkstyle" , checkstyle) ?;
832846 cx. export_function ( "clean" , clean) ?;
@@ -887,7 +901,7 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
887901
888902#[ cfg( test) ]
889903mod test {
890- use std:: { env , process:: Command } ;
904+ use std:: process:: Command ;
891905 use tmc_server_mock:: mockito:: Server ;
892906
893907 fn init ( ) {
@@ -905,13 +919,13 @@ mod test {
905919 init ( ) ;
906920 let mut server = Server :: new ( ) ;
907921 tmc_server_mock:: mock_all ( & mut server) ;
908- env:: set_var (
909- "TMC_LANGS_MOCK_SERVER_ADDR" ,
910- format ! ( "http://{}" , server. host_with_port( ) ) ,
911- ) ;
912922
913923 let s = Command :: new ( "npm" )
914924 . args ( [ "run" , "jest" ] )
925+ . env (
926+ "TMC_LANGS_MOCK_SERVER_ADDR" ,
927+ format ! ( "http://{}" , server. host_with_port( ) ) ,
928+ )
915929 . output ( )
916930 . expect ( "running jest failed" ) ;
917931 println ! ( "stdout: {}" , String :: from_utf8_lossy( & s. stdout) ) ;
0 commit comments