core: Fix path building error handling.
This commit is contained in:
parent
0578725876
commit
a476372a54
|
@ -78,6 +78,13 @@ impl fmt::Display for RookeriesError {
|
|||
file_type.to_string().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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,10 @@ use crate::errors::RookeriesError;
|
|||
use crate::success_message;
|
||||
use colored::Colorize;
|
||||
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???";
|
||||
|
||||
|
@ -119,7 +122,7 @@ pub fn create_directory(
|
|||
|
||||
pub fn build_path(built_path: &Path, file_type: FileType) -> Result<PathBuf, RookeriesError> {
|
||||
built_path.canonicalize().map_err(|err| {
|
||||
let path_causing_error = built_path.to_str().unwrap_or(ROOKERIES_UNKNOWN_FILE).to_string();
|
||||
RookeriesError::PathBuilderError(err, path_causing_error, file_type)
|
||||
let error_path = built_path.to_string_lossy().to_string();
|
||||
RookeriesError::PathBuilderError(err, error_path, file_type)
|
||||
})
|
||||
}
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -22,7 +22,7 @@ use colored::Colorize;
|
|||
use docopt::Docopt;
|
||||
use env_logger::{Builder, Env};
|
||||
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 serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
|
@ -382,10 +382,7 @@ fn build_site(args: &Args) -> Result {
|
|||
.join("static")
|
||||
.canonicalize()
|
||||
.expect("Unable to build canonical path to assets.");
|
||||
let assets_target_dir = build_directory(Path::new(&build_directory), Fi
|
||||
.join("static")
|
||||
.canonicalize()
|
||||
.expect("Eek pathing probs.");
|
||||
let assets_target_dir = Path::new(&build_directory).join("static");
|
||||
header_message("Copying static assets to built site...");
|
||||
copy_directory(
|
||||
&assets_source_dir,
|
||||
|
@ -399,8 +396,10 @@ fn build_site(args: &Args) -> Result {
|
|||
header_message("Activate plugins...");
|
||||
// TODO: Copy over only active and available markdown plugins.
|
||||
let plugin_list = vec!["hello-world", "dark-mode-switch"];
|
||||
let plugins_install_path = build_path(Path::new(&project_directory),
|
||||
FileType::Plugin)?;
|
||||
let plugins_install_path = build_path(
|
||||
&Path::new(&project_directory).join("plugins"),
|
||||
FileType::Plugin,
|
||||
)?;
|
||||
|
||||
let static_js_path = Path::new(&assets_target_dir).join("js");
|
||||
for plugin in plugin_list {
|
||||
|
|
Loading…
Reference in New Issue