core: Fix path building error handling.

This commit is contained in:
Dorian 2019-09-12 08:50:41 -04:00
parent 0578725876
commit a476372a54
3 changed files with 19 additions and 10 deletions

View File

@ -78,6 +78,13 @@ impl fmt::Display for RookeriesError {
file_type.to_string().red(), file_type.to_string().red(),
path.red() path.red()
)?; )?;
if path.find(std::char::REPLACEMENT_CHARACTER).is_some() {
writeln!(
f,
"The path {} contains characters that could not be encoded to UTF-8!",
path.red()
)?;
}
write!(f, "Exact cause: {}", err) write!(f, "Exact cause: {}", err)
} }
} }

View File

@ -2,7 +2,10 @@ use crate::errors::RookeriesError;
use crate::success_message; use crate::success_message;
use colored::Colorize; use colored::Colorize;
use copy_dir::copy_dir; use copy_dir::copy_dir;
use std::{fmt, fs, io, path::{Path, PathBuf}}; use std::{
fmt, fs, io,
path::{Path, PathBuf},
};
const ROOKERIES_UNKNOWN_FILE: &'static str = "UNKNOWN_FILE???"; const ROOKERIES_UNKNOWN_FILE: &'static str = "UNKNOWN_FILE???";
@ -119,7 +122,7 @@ pub fn create_directory(
pub fn build_path(built_path: &Path, file_type: FileType) -> Result<PathBuf, RookeriesError> { pub fn build_path(built_path: &Path, file_type: FileType) -> Result<PathBuf, RookeriesError> {
built_path.canonicalize().map_err(|err| { built_path.canonicalize().map_err(|err| {
let path_causing_error = built_path.to_str().unwrap_or(ROOKERIES_UNKNOWN_FILE).to_string(); let error_path = built_path.to_string_lossy().to_string();
RookeriesError::PathBuilderError(err, path_causing_error, file_type) RookeriesError::PathBuilderError(err, error_path, file_type)
}) })
} }

View File

@ -22,7 +22,7 @@ use colored::Colorize;
use docopt::Docopt; use docopt::Docopt;
use env_logger::{Builder, Env}; use env_logger::{Builder, Env};
use rookeries::errors::{fatal_error, RookeriesError}; use rookeries::errors::{fatal_error, RookeriesError};
use rookeries::files::{copy_directory, copy_file, create_directory, FileType, build_path}; use rookeries::files::{build_path, copy_directory, copy_file, create_directory, FileType};
use rookeries::{caution_message, header_message, success_message, Page, Site}; use rookeries::{caution_message, header_message, success_message, Page, Site};
use serde_json::Value; use serde_json::Value;
use std::collections::HashMap; use std::collections::HashMap;
@ -382,10 +382,7 @@ fn build_site(args: &Args) -> Result {
.join("static") .join("static")
.canonicalize() .canonicalize()
.expect("Unable to build canonical path to assets."); .expect("Unable to build canonical path to assets.");
let assets_target_dir = build_directory(Path::new(&build_directory), Fi let assets_target_dir = Path::new(&build_directory).join("static");
.join("static")
.canonicalize()
.expect("Eek pathing probs.");
header_message("Copying static assets to built site..."); header_message("Copying static assets to built site...");
copy_directory( copy_directory(
&assets_source_dir, &assets_source_dir,
@ -399,8 +396,10 @@ fn build_site(args: &Args) -> Result {
header_message("Activate plugins..."); header_message("Activate plugins...");
// TODO: Copy over only active and available markdown plugins. // TODO: Copy over only active and available markdown plugins.
let plugin_list = vec!["hello-world", "dark-mode-switch"]; let plugin_list = vec!["hello-world", "dark-mode-switch"];
let plugins_install_path = build_path(Path::new(&project_directory), let plugins_install_path = build_path(
FileType::Plugin)?; &Path::new(&project_directory).join("plugins"),
FileType::Plugin,
)?;
let static_js_path = Path::new(&assets_target_dir).join("js"); let static_js_path = Path::new(&assets_target_dir).join("js");
for plugin in plugin_list { for plugin in plugin_list {