@@ -16,14 +16,13 @@ use std::{
16
16
} ;
17
17
use thiserror:: Error ;
18
18
use tmc_langs:: {
19
- file_util,
19
+ Compression , Credentials , DownloadOrUpdateCourseExercisesResult , LangsError , Language ,
20
+ PrepareSubmission , TmcConfig , file_util,
20
21
tmc:: {
22
+ TestMyCodeClient , TestMyCodeClientError ,
21
23
request:: FeedbackAnswer ,
22
24
response:: { NewSubmission , SubmissionFinished } ,
23
- TestMyCodeClient , TestMyCodeClientError ,
24
25
} ,
25
- Compression , Credentials , DownloadOrUpdateCourseExercisesResult , LangsError , Language ,
26
- PrepareSubmission , TmcConfig ,
27
26
} ;
28
27
29
28
#[ derive( Debug , Error ) ]
@@ -82,12 +81,6 @@ pub fn init_logging(mut cx: FunctionContext) -> JsResult<JsNull> {
82
81
Ok ( cx. null ( ) )
83
82
}
84
83
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
-
91
84
fn checkstyle ( mut cx : FunctionContext ) -> JsResult < JsValue > {
92
85
parse_args ! ( cx, exercise_path: PathBuf , locale: String ) ;
93
86
lock ! ( cx, exercise_path) ;
@@ -304,7 +297,9 @@ fn download_model_solution(mut cx: FunctionContext) -> JsResult<JsValue> {
304
297
) ;
305
298
306
299
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) ?)
308
303
} ) ;
309
304
convert_res ( & mut cx, res)
310
305
}
@@ -398,7 +393,7 @@ fn get_course_details(mut cx: FunctionContext) -> JsResult<JsValue> {
398
393
) ;
399
394
400
395
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 ) ?)
402
397
} ) ;
403
398
convert_res ( & mut cx, res)
404
399
}
@@ -412,7 +407,7 @@ fn get_course_exercises(mut cx: FunctionContext) -> JsResult<JsValue> {
412
407
) ;
413
408
414
409
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 ) ?)
416
411
} ) ;
417
412
convert_res ( & mut cx, res)
418
413
}
@@ -426,7 +421,7 @@ fn get_course_settings(mut cx: FunctionContext) -> JsResult<JsValue> {
426
421
) ;
427
422
428
423
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 ) ?)
430
425
} ) ;
431
426
convert_res ( & mut cx, res)
432
427
}
@@ -440,7 +435,7 @@ fn get_courses(mut cx: FunctionContext) -> JsResult<JsValue> {
440
435
) ;
441
436
442
437
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 ) ?)
444
439
} ) ;
445
440
convert_res ( & mut cx, res)
446
441
}
@@ -454,7 +449,7 @@ fn get_exercise_details(mut cx: FunctionContext) -> JsResult<JsValue> {
454
449
) ;
455
450
456
451
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 ) ?)
458
453
} ) ;
459
454
convert_res ( & mut cx, res)
460
455
}
@@ -468,7 +463,9 @@ fn get_exercise_submissions(mut cx: FunctionContext) -> JsResult<JsValue> {
468
463
) ;
469
464
470
465
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) ?)
472
469
} ) ;
473
470
convert_res ( & mut cx, res)
474
471
}
@@ -484,7 +481,9 @@ fn get_exercise_updates(mut cx: FunctionContext) -> JsResult<JsValue> {
484
481
485
482
let map = exercise. into_iter ( ) . collect ( ) ;
486
483
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) ?)
488
487
} ) ;
489
488
convert_res ( & mut cx, res)
490
489
}
@@ -498,7 +497,7 @@ fn get_organization(mut cx: FunctionContext) -> JsResult<JsValue> {
498
497
) ;
499
498
500
499
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 ) ?)
502
501
} ) ;
503
502
convert_res ( & mut cx, res)
504
503
}
@@ -507,7 +506,7 @@ fn get_organizations(mut cx: FunctionContext) -> JsResult<JsValue> {
507
506
parse_args ! ( cx, client_name: String , client_version: String ) ;
508
507
509
508
let res = with_client ( client_name, client_version, |client| {
510
- Ok ( client. get_organizations ( ) ?)
509
+ Ok ( client. get_organizations ( ) . map_err ( Box :: new ) ?)
511
510
} ) ;
512
511
convert_res ( & mut cx, res)
513
512
}
@@ -521,7 +520,7 @@ fn get_unread_reviews(mut cx: FunctionContext) -> JsResult<JsValue> {
521
520
) ;
522
521
523
522
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 ) ?)
525
524
} ) ;
526
525
convert_res ( & mut cx, res)
527
526
}
@@ -600,7 +599,9 @@ fn mark_review_as_read(mut cx: FunctionContext) -> JsResult<JsValue> {
600
599
) ;
601
600
602
601
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) ?)
604
605
} ) ;
605
606
convert_res ( & mut cx, res)
606
607
}
@@ -619,7 +620,9 @@ fn paste(mut cx: FunctionContext) -> JsResult<JsValue> {
619
620
620
621
let locale = locale. map ( |l| Language :: from_639_3 ( & l) . expect ( "Invalid locale" ) ) ;
621
622
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) ?)
623
626
} ) ;
624
627
convert_res ( & mut cx, res)
625
628
}
@@ -638,12 +641,14 @@ fn request_code_review(mut cx: FunctionContext) -> JsResult<JsValue> {
638
641
639
642
let locale = Language :: from_639_3 ( & locale) . expect ( "Invalid locale" ) ;
640
643
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) ?)
647
652
} ) ;
648
653
convert_res ( & mut cx, res)
649
654
}
@@ -661,7 +666,9 @@ fn reset_exercise(mut cx: FunctionContext) -> JsResult<JsValue> {
661
666
662
667
let res = with_client ( client_name, client_version, |client| {
663
668
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) ?;
665
672
}
666
673
tmc_langs:: reset ( client, exercise_id, & exercise_path)
667
674
} ) ;
@@ -685,7 +692,9 @@ fn send_feedback(mut cx: FunctionContext) -> JsResult<JsValue> {
685
692
} )
686
693
. collect ( ) ;
687
694
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) ?)
689
698
} ) ;
690
699
convert_res ( & mut cx, res)
691
700
}
@@ -708,15 +717,19 @@ fn submit(mut cx: FunctionContext) -> JsResult<JsValue> {
708
717
709
718
let locale = locale. map ( |l| Language :: from_639_3 ( & l) . expect ( "Invalid locale" ) ) ;
710
719
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) ?;
712
723
if dont_block {
713
724
Ok ( Temp :: NewSubmission ( new_submission) )
714
725
} else {
715
726
let submission_url = new_submission
716
727
. submission_url
717
728
. parse ( )
718
729
. 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) ?;
720
733
Ok ( Temp :: Finished ( Box :: new ( finished) ) )
721
734
}
722
735
} )
@@ -747,7 +760,9 @@ fn wait_for_submission(mut cx: FunctionContext) -> JsResult<JsValue> {
747
760
) ;
748
761
749
762
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) ?)
751
766
} ) ;
752
767
convert_res ( & mut cx, res)
753
768
}
@@ -826,7 +841,6 @@ fn unset_setting(mut cx: FunctionContext) -> JsResult<JsValue> {
826
841
#[ neon:: main]
827
842
fn main ( mut cx : ModuleContext ) -> NeonResult < ( ) > {
828
843
cx. export_function ( "initLogging" , init_logging) ?;
829
- cx. export_function ( "setEnv" , set_env) ?;
830
844
831
845
cx. export_function ( "checkstyle" , checkstyle) ?;
832
846
cx. export_function ( "clean" , clean) ?;
@@ -887,7 +901,7 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
887
901
888
902
#[ cfg( test) ]
889
903
mod test {
890
- use std:: { env , process:: Command } ;
904
+ use std:: process:: Command ;
891
905
use tmc_server_mock:: mockito:: Server ;
892
906
893
907
fn init ( ) {
@@ -905,13 +919,13 @@ mod test {
905
919
init ( ) ;
906
920
let mut server = Server :: new ( ) ;
907
921
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
- ) ;
912
922
913
923
let s = Command :: new ( "npm" )
914
924
. args ( [ "run" , "jest" ] )
925
+ . env (
926
+ "TMC_LANGS_MOCK_SERVER_ADDR" ,
927
+ format ! ( "http://{}" , server. host_with_port( ) ) ,
928
+ )
915
929
. output ( )
916
930
. expect ( "running jest failed" ) ;
917
931
println ! ( "stdout: {}" , String :: from_utf8_lossy( & s. stdout) ) ;
0 commit comments