Handle unwraps

This commit is contained in:
raychu86 2020-08-16 18:15:53 -07:00
parent 82bac674e9
commit 953de07b56
3 changed files with 13 additions and 4 deletions

View File

@ -113,10 +113,17 @@ impl CLI for AddCommand {
let bytes = response.bytes()?;
let reader = std::io::Cursor::new(bytes);
let mut zip_arhive = zip::ZipArchive::new(reader).unwrap();
let mut zip_arhive = match zip::ZipArchive::new(reader) {
Ok(zip) => zip,
Err(error) => return Err(AddError(ZipError(error.to_string().into()))),
};
for i in 0..zip_arhive.len() {
let file = zip_arhive.by_index(i).unwrap();
let file = match zip_arhive.by_index(i) {
Ok(file) => file,
Err(error) => return Err(AddError(ZipError(error.to_string().into()))),
};
let file_name = file.name();
let mut file_path = path.clone();

View File

@ -2,7 +2,7 @@ use crate::{
cli::*,
cli_types::*,
commands::LoginCommand,
credentials::read_token,
credentials::{read_token, PACKAGE_MANAGER_URL},
errors::{
commands::PublishError::{ConnectionUnavalaible, PackageNotPublished},
CLIError,
@ -22,7 +22,6 @@ use reqwest::{
use serde::Deserialize;
use std::{convert::TryFrom, env::current_dir};
const PACKAGE_MANAGER_URL: &str = "https://apm-backend-dev.herokuapp.com/";
const PUBLISH_URL: &str = "api/package/publish";
#[derive(Deserialize)]

View File

@ -7,4 +7,7 @@ pub enum AddError {
#[error("missing author or package name")]
MissingAuthorOrPackageName,
#[error("{:?}", _0)]
ZipError(OsString),
}