|
1 | 1 | use crate::buildomat_builder::*; |
| 2 | +use anyhow::Context as _; |
2 | 3 | pub struct Cli<T: CliConfig> { |
3 | 4 | client: Client, |
4 | 5 | config: T, |
@@ -465,8 +466,10 @@ impl<T: CliConfig> Cli<T> { |
465 | 466 | } |
466 | 467 |
|
467 | 468 | if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") { |
468 | | - let body_txt = std::fs::read_to_string(value).unwrap(); |
469 | | - let body_value = serde_json::from_str::<types::TaskSubmit>(&body_txt).unwrap(); |
| 469 | + let body_txt = std::fs::read_to_string(value) |
| 470 | + .with_context(|| format!("failed to read {}", value.display()))?; |
| 471 | + let body_value = serde_json::from_str::<types::TaskSubmit>(&body_txt) |
| 472 | + .with_context(|| format!("failed to parse {}", value.display()))?; |
470 | 473 | request = request.body(body_value); |
471 | 474 | } |
472 | 475 |
|
@@ -569,8 +572,10 @@ impl<T: CliConfig> Cli<T> { |
569 | 572 | } |
570 | 573 |
|
571 | 574 | if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") { |
572 | | - let body_txt = std::fs::read_to_string(value).unwrap(); |
573 | | - let body_value = serde_json::from_str::<types::UserCreate>(&body_txt).unwrap(); |
| 575 | + let body_txt = std::fs::read_to_string(value) |
| 576 | + .with_context(|| format!("failed to read {}", value.display()))?; |
| 577 | + let body_value = serde_json::from_str::<types::UserCreate>(&body_txt) |
| 578 | + .with_context(|| format!("failed to parse {}", value.display()))?; |
574 | 579 | request = request.body(body_value); |
575 | 580 | } |
576 | 581 |
|
@@ -637,8 +642,10 @@ impl<T: CliConfig> Cli<T> { |
637 | 642 | } |
638 | 643 |
|
639 | 644 | if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") { |
640 | | - let body_txt = std::fs::read_to_string(value).unwrap(); |
641 | | - let body_value = serde_json::from_str::<types::WorkerBootstrap>(&body_txt).unwrap(); |
| 645 | + let body_txt = std::fs::read_to_string(value) |
| 646 | + .with_context(|| format!("failed to read {}", value.display()))?; |
| 647 | + let body_value = serde_json::from_str::<types::WorkerBootstrap>(&body_txt) |
| 648 | + .with_context(|| format!("failed to parse {}", value.display()))?; |
642 | 649 | request = request.body(body_value); |
643 | 650 | } |
644 | 651 |
|
@@ -695,8 +702,10 @@ impl<T: CliConfig> Cli<T> { |
695 | 702 | } |
696 | 703 |
|
697 | 704 | if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") { |
698 | | - let body_txt = std::fs::read_to_string(value).unwrap(); |
699 | | - let body_value = serde_json::from_str::<types::WorkerAppendTask>(&body_txt).unwrap(); |
| 705 | + let body_txt = std::fs::read_to_string(value) |
| 706 | + .with_context(|| format!("failed to read {}", value.display()))?; |
| 707 | + let body_value = serde_json::from_str::<types::WorkerAppendTask>(&body_txt) |
| 708 | + .with_context(|| format!("failed to parse {}", value.display()))?; |
700 | 709 | request = request.body(body_value); |
701 | 710 | } |
702 | 711 |
|
@@ -753,8 +762,10 @@ impl<T: CliConfig> Cli<T> { |
753 | 762 | } |
754 | 763 |
|
755 | 764 | if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") { |
756 | | - let body_txt = std::fs::read_to_string(value).unwrap(); |
757 | | - let body_value = serde_json::from_str::<types::WorkerCompleteTask>(&body_txt).unwrap(); |
| 765 | + let body_txt = std::fs::read_to_string(value) |
| 766 | + .with_context(|| format!("failed to read {}", value.display()))?; |
| 767 | + let body_value = serde_json::from_str::<types::WorkerCompleteTask>(&body_txt) |
| 768 | + .with_context(|| format!("failed to parse {}", value.display()))?; |
758 | 769 | request = request.body(body_value); |
759 | 770 | } |
760 | 771 |
|
@@ -791,8 +802,10 @@ impl<T: CliConfig> Cli<T> { |
791 | 802 | } |
792 | 803 |
|
793 | 804 | if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") { |
794 | | - let body_txt = std::fs::read_to_string(value).unwrap(); |
795 | | - let body_value = serde_json::from_str::<types::WorkerAddOutput>(&body_txt).unwrap(); |
| 805 | + let body_txt = std::fs::read_to_string(value) |
| 806 | + .with_context(|| format!("failed to read {}", value.display()))?; |
| 807 | + let body_value = serde_json::from_str::<types::WorkerAddOutput>(&body_txt) |
| 808 | + .with_context(|| format!("failed to parse {}", value.display()))?; |
796 | 809 | request = request.body(body_value); |
797 | 810 | } |
798 | 811 |
|
|
0 commit comments