Skip to content

Commit 18fd06e

Browse files
committed
Clippy
1 parent f2dab1c commit 18fd06e

File tree

6 files changed

+62
-107
lines changed

6 files changed

+62
-107
lines changed

crates/bindings/tmc-langs-node/src/lib.rs

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,7 @@ fn download_model_solution(mut cx: FunctionContext) -> JsResult<JsValue> {
297297
);
298298

299299
let res = with_client(client_name, client_version, |client| {
300-
Ok(client
301-
.download_model_solution(exercise_id, &target)
302-
.map_err(Box::new)?)
300+
Ok(client.download_model_solution(exercise_id, &target)?)
303301
});
304302
convert_res(&mut cx, res)
305303
}
@@ -393,7 +391,7 @@ fn get_course_details(mut cx: FunctionContext) -> JsResult<JsValue> {
393391
);
394392

395393
let res = with_client(client_name, client_version, |client| {
396-
Ok(client.get_course_details(course_id).map_err(Box::new)?)
394+
Ok(client.get_course_details(course_id)?)
397395
});
398396
convert_res(&mut cx, res)
399397
}
@@ -407,7 +405,7 @@ fn get_course_exercises(mut cx: FunctionContext) -> JsResult<JsValue> {
407405
);
408406

409407
let res = with_client(client_name, client_version, |client| {
410-
Ok(client.get_course_exercises(course_id).map_err(Box::new)?)
408+
Ok(client.get_course_exercises(course_id)?)
411409
});
412410
convert_res(&mut cx, res)
413411
}
@@ -421,7 +419,7 @@ fn get_course_settings(mut cx: FunctionContext) -> JsResult<JsValue> {
421419
);
422420

423421
let res = with_client(client_name, client_version, |client| {
424-
Ok(client.get_course(course_id).map_err(Box::new)?)
422+
Ok(client.get_course(course_id)?)
425423
});
426424
convert_res(&mut cx, res)
427425
}
@@ -435,7 +433,7 @@ fn get_courses(mut cx: FunctionContext) -> JsResult<JsValue> {
435433
);
436434

437435
let res = with_client(client_name, client_version, |client| {
438-
Ok(client.list_courses(&organization).map_err(Box::new)?)
436+
Ok(client.list_courses(&organization)?)
439437
});
440438
convert_res(&mut cx, res)
441439
}
@@ -449,7 +447,7 @@ fn get_exercise_details(mut cx: FunctionContext) -> JsResult<JsValue> {
449447
);
450448

451449
let res = with_client(client_name, client_version, |client| {
452-
Ok(client.get_exercise_details(exercise_id).map_err(Box::new)?)
450+
Ok(client.get_exercise_details(exercise_id)?)
453451
});
454452
convert_res(&mut cx, res)
455453
}
@@ -463,9 +461,7 @@ fn get_exercise_submissions(mut cx: FunctionContext) -> JsResult<JsValue> {
463461
);
464462

465463
let res = with_client(client_name, client_version, |client| {
466-
Ok(client
467-
.get_exercise_submissions_for_current_user(exercise_id)
468-
.map_err(Box::new)?)
464+
Ok(client.get_exercise_submissions_for_current_user(exercise_id)?)
469465
});
470466
convert_res(&mut cx, res)
471467
}
@@ -481,9 +477,7 @@ fn get_exercise_updates(mut cx: FunctionContext) -> JsResult<JsValue> {
481477

482478
let map = exercise.into_iter().collect();
483479
let res = with_client(client_name, client_version, |client| {
484-
Ok(client
485-
.get_exercise_updates(course_id, map)
486-
.map_err(Box::new)?)
480+
Ok(client.get_exercise_updates(course_id, map)?)
487481
});
488482
convert_res(&mut cx, res)
489483
}
@@ -497,7 +491,7 @@ fn get_organization(mut cx: FunctionContext) -> JsResult<JsValue> {
497491
);
498492

499493
let res = with_client(client_name, client_version, |client| {
500-
Ok(client.get_organization(&organization).map_err(Box::new)?)
494+
Ok(client.get_organization(&organization)?)
501495
});
502496
convert_res(&mut cx, res)
503497
}
@@ -506,7 +500,7 @@ fn get_organizations(mut cx: FunctionContext) -> JsResult<JsValue> {
506500
parse_args!(cx, client_name: String, client_version: String);
507501

508502
let res = with_client(client_name, client_version, |client| {
509-
Ok(client.get_organizations().map_err(Box::new)?)
503+
Ok(client.get_organizations()?)
510504
});
511505
convert_res(&mut cx, res)
512506
}
@@ -520,7 +514,7 @@ fn get_unread_reviews(mut cx: FunctionContext) -> JsResult<JsValue> {
520514
);
521515

522516
let res = with_client(client_name, client_version, |client| {
523-
Ok(client.get_unread_reviews(course_id).map_err(Box::new)?)
517+
Ok(client.get_unread_reviews(course_id)?)
524518
});
525519
convert_res(&mut cx, res)
526520
}
@@ -599,9 +593,7 @@ fn mark_review_as_read(mut cx: FunctionContext) -> JsResult<JsValue> {
599593
);
600594

601595
let res = with_client(client_name, client_version, |client| {
602-
Ok(client
603-
.mark_review_as_read(course_id, review_id)
604-
.map_err(Box::new)?)
596+
Ok(client.mark_review_as_read(course_id, review_id)?)
605597
});
606598
convert_res(&mut cx, res)
607599
}
@@ -620,9 +612,7 @@ fn paste(mut cx: FunctionContext) -> JsResult<JsValue> {
620612

621613
let locale = locale.map(|l| Language::from_639_3(&l).expect("Invalid locale"));
622614
let res = with_client(client_name, client_version, |client| {
623-
Ok(client
624-
.paste(exercise_id, &submission_path, paste_message, locale)
625-
.map_err(Box::new)?)
615+
Ok(client.paste(exercise_id, &submission_path, paste_message, locale)?)
626616
});
627617
convert_res(&mut cx, res)
628618
}
@@ -641,14 +631,12 @@ fn request_code_review(mut cx: FunctionContext) -> JsResult<JsValue> {
641631

642632
let locale = Language::from_639_3(&locale).expect("Invalid locale");
643633
let res = with_client(client_name, client_version, |client| {
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)?)
634+
Ok(client.request_code_review(
635+
exercise_id,
636+
&submission_path,
637+
message_for_reviewer,
638+
Some(locale),
639+
)?)
652640
});
653641
convert_res(&mut cx, res)
654642
}
@@ -666,9 +654,7 @@ fn reset_exercise(mut cx: FunctionContext) -> JsResult<JsValue> {
666654

667655
let res = with_client(client_name, client_version, |client| {
668656
if save_old_state {
669-
client
670-
.submit(exercise_id, &exercise_path, None)
671-
.map_err(Box::new)?;
657+
client.submit(exercise_id, &exercise_path, None)?;
672658
}
673659
tmc_langs::reset(client, exercise_id, &exercise_path)
674660
});
@@ -692,9 +678,7 @@ fn send_feedback(mut cx: FunctionContext) -> JsResult<JsValue> {
692678
})
693679
.collect();
694680
let res = with_client(client_name, client_version, |client| {
695-
Ok(client
696-
.send_feedback(submission_id, feedback)
697-
.map_err(Box::new)?)
681+
Ok(client.send_feedback(submission_id, feedback)?)
698682
});
699683
convert_res(&mut cx, res)
700684
}
@@ -717,19 +701,15 @@ fn submit(mut cx: FunctionContext) -> JsResult<JsValue> {
717701

718702
let locale = locale.map(|l| Language::from_639_3(&l).expect("Invalid locale"));
719703
let temp = with_client(client_name, client_version, |client| {
720-
let new_submission = client
721-
.submit(exercise_id, &submission_path, locale)
722-
.map_err(Box::new)?;
704+
let new_submission = client.submit(exercise_id, &submission_path, locale)?;
723705
if dont_block {
724706
Ok(Temp::NewSubmission(new_submission))
725707
} else {
726708
let submission_url = new_submission
727709
.submission_url
728710
.parse()
729711
.expect("Failed to parse submission URL");
730-
let finished = client
731-
.wait_for_submission_at(submission_url)
732-
.map_err(Box::new)?;
712+
let finished = client.wait_for_submission_at(submission_url)?;
733713
Ok(Temp::Finished(Box::new(finished)))
734714
}
735715
})
@@ -760,9 +740,7 @@ fn wait_for_submission(mut cx: FunctionContext) -> JsResult<JsValue> {
760740
);
761741

762742
let res = with_client(client_name, client_version, |client| {
763-
Ok(client
764-
.wait_for_submission(submission_id)
765-
.map_err(Box::new)?)
743+
Ok(client.wait_for_submission(submission_id)?)
766744
});
767745
convert_res(&mut cx, res)
768746
}

crates/tmc-langs/src/lib.rs

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ pub fn check_exercise_updates(
120120
if !local_exercises.is_empty() {
121121
let exercise_ids = local_exercises.iter().map(|e| e.id).collect::<Vec<_>>();
122122
let server_exercises = client
123-
.get_exercises_details(&exercise_ids)
124-
.map_err(Box::new)?
123+
.get_exercises_details(&exercise_ids)?
125124
.into_iter()
126125
.map(|e| (e.id, e))
127126
.collect::<HashMap<_, _>>();
@@ -152,9 +151,7 @@ pub fn download_old_submission(
152151

153152
if save_old_state {
154153
// submit old exercise
155-
client
156-
.submit(exercise_id, output_path, None)
157-
.map_err(Box::new)?;
154+
client.submit(exercise_id, output_path, None)?;
158155
log::debug!("finished submission");
159156
}
160157

@@ -164,9 +161,7 @@ pub fn download_old_submission(
164161

165162
// dl submission
166163
let mut buf = vec![];
167-
client
168-
.download_old_submission(submission_id, &mut buf)
169-
.map_err(Box::new)?;
164+
client.download_old_submission(submission_id, &mut buf)?;
170165
log::debug!("downloaded old submission");
171166

172167
// extract submission
@@ -193,7 +188,6 @@ pub fn submit_exercise(
193188

194189
client
195190
.submit(exercise.id, exercise_path.as_path(), locale)
196-
.map_err(Box::new)
197191
.map_err(Into::into)
198192
}
199193

@@ -216,7 +210,6 @@ pub fn paste_exercise(
216210

217211
client
218212
.paste(exercise.id, exercise_path.as_path(), paste_message, locale)
219-
.map_err(Box::new)
220213
.map_err(Into::into)
221214
}
222215

@@ -239,7 +232,7 @@ pub fn download_or_update_course_exercises(
239232

240233
client.require_authentication().map_err(Box::new)?;
241234

242-
let exercises_details = client.get_exercises_details(exercises).map_err(Box::new)?;
235+
let exercises_details = client.get_exercises_details(exercises)?;
243236
let projects_config = ProjectsConfig::load(projects_dir)?;
244237

245238
// separate exercises into downloads and skipped
@@ -279,8 +272,7 @@ pub fn download_or_update_course_exercises(
279272
// not on disk, if flag isn't set check if there are any previous submissions and take the latest one if so
280273
if !download_template {
281274
if let Some(latest_submission) = client
282-
.get_exercise_submissions_for_current_user(exercise_detail.id)
283-
.map_err(Box::new)?
275+
.get_exercise_submissions_for_current_user(exercise_detail.id)?
284276
.into_iter()
285277
.max_by_key(|s| s.created_at)
286278
{
@@ -371,9 +363,7 @@ pub fn download_or_update_course_exercises(
371363
match &download_target.kind {
372364
DownloadTargetKind::Template => {
373365
let mut buf = vec![];
374-
client
375-
.download_exercise(download_target.target.id, &mut buf)
376-
.map_err(Box::new)?;
366+
client.download_exercise(download_target.target.id, &mut buf)?;
377367
extract_project(
378368
Cursor::new(buf),
379369
&download_target.target.path,
@@ -384,9 +374,7 @@ pub fn download_or_update_course_exercises(
384374
}
385375
DownloadTargetKind::Submission { submission_id } => {
386376
let mut buf = vec![];
387-
client
388-
.download_exercise(download_target.target.id, &mut buf)
389-
.map_err(Box::new)?;
377+
client.download_exercise(download_target.target.id, &mut buf)?;
390378
extract_project(
391379
Cursor::new(buf),
392380
&download_target.target.path,
@@ -409,9 +397,7 @@ pub fn download_or_update_course_exercises(
409397
}
410398

411399
let mut buf = vec![];
412-
client
413-
.download_old_submission(*submission_id, &mut buf)
414-
.map_err(Box::new)?;
400+
client.download_old_submission(*submission_id, &mut buf)?;
415401
if let Err(err) = plugin.extract_student_files(
416402
Cursor::new(buf),
417403
Compression::Zip,
@@ -539,9 +525,9 @@ pub fn get_course_data(
539525
) -> Result<CombinedCourseData, LangsError> {
540526
log::debug!("getting course data for {course_id}");
541527

542-
let details = client.get_course_details(course_id).map_err(Box::new)?;
543-
let exercises = client.get_course_exercises(course_id).map_err(Box::new)?;
544-
let settings = client.get_course(course_id).map_err(Box::new)?;
528+
let details = client.get_course_details(course_id)?;
529+
let exercises = client.get_course_exercises(course_id)?;
530+
let settings = client.get_course(course_id)?;
545531
Ok(CombinedCourseData {
546532
details,
547533
exercises,
@@ -571,9 +557,7 @@ pub fn login_with_password(
571557
password: String,
572558
) -> Result<tmc::Token, LangsError> {
573559
log::debug!("logging in with password");
574-
let token = client
575-
.authenticate(client_name, email, password)
576-
.map_err(Box::new)?;
560+
let token = client.authenticate(client_name, email, password)?;
577561
Ok(token)
578562
}
579563

@@ -588,8 +572,7 @@ pub fn init_testmycode_client_with_credentials(
588572
root_url,
589573
client_name.to_string(),
590574
client_version.to_string(),
591-
)
592-
.map_err(Box::new)?;
575+
)?;
593576

594577
// set token from the credentials file if one exists
595578
let credentials = Credentials::load(client_name)?;
@@ -640,8 +623,7 @@ pub fn update_tmc_exercises(
640623
if !exercises.is_empty() {
641624
let tmc_exercise_ids = exercises.iter().map(|e| e.id).collect::<Vec<_>>();
642625
let mut tmc_server_exercises = client
643-
.get_exercises_details(&tmc_exercise_ids)
644-
.map_err(Box::new)?
626+
.get_exercises_details(&tmc_exercise_ids)?
645627
.into_iter()
646628
.map(|e| (e.id, e))
647629
.collect::<HashMap<_, _>>();
@@ -681,9 +663,7 @@ pub fn update_tmc_exercises(
681663
if !exercises_to_update.is_empty() {
682664
for exercise in &exercises_to_update {
683665
let mut buf = vec![];
684-
client
685-
.download_exercise(exercise.id, &mut buf)
686-
.map_err(Box::new)?;
666+
client.download_exercise(exercise.id, &mut buf)?;
687667
extract_project(
688668
Cursor::new(buf),
689669
&exercise.path,
@@ -741,19 +721,15 @@ pub fn update_mooc_exercises(
741721
checksum: &e.checksum,
742722
})
743723
.collect::<Vec<_>>();
744-
let exercise_updates = client
745-
.check_exercise_updates(&exercise_update_data)
746-
.map_err(Box::new)?;
724+
let exercise_updates = client.check_exercise_updates(&exercise_update_data)?;
747725
for updated_exercise in exercise_updates.updated_exercises {
748726
if let Some((course, exercise)) = exercises.get(&updated_exercise) {
749727
let target = ProjectsConfig::get_mooc_exercise_download_target(
750728
projects_dir,
751729
&course.directory,
752730
&exercise.directory,
753731
);
754-
let data = client
755-
.download_exercise(updated_exercise)
756-
.map_err(Box::new)?;
732+
let data = client.download_exercise(updated_exercise)?;
757733
extract_project(Cursor::new(data), &target, Compression::Zip, false, false)?;
758734
downloaded.push(MoocExerciseDownload {
759735
id: updated_exercise,
@@ -923,9 +899,7 @@ pub fn reset(
923899
file_util::remove_dir_all(exercise_path)?;
924900
}
925901
let mut buf = vec![];
926-
client
927-
.download_exercise(exercise_id, &mut buf)
928-
.map_err(Box::new)?;
902+
client.download_exercise(exercise_id, &mut buf)?;
929903
extract_project(
930904
Cursor::new(buf),
931905
exercise_path,

crates/tmc-mooc-client/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use reqwest::{Method, StatusCode, Url};
44
use std::error::Error;
55
use thiserror::Error;
66

7-
pub type MoocClientResult<T> = Result<T, MoocClientError>;
7+
pub type MoocClientResult<T> = Result<T, Box<MoocClientError>>;
88

99
#[derive(Debug, Error)]
1010
pub enum MoocClientError {

0 commit comments

Comments
 (0)