Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions diesel_cli/src/print_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer};
use std::error::Error;
use std::fmt::{self, Display, Formatter, Write};
use std::fs::File;
use std::io::{self, Write as IoWrite};
use std::io::{self, Error as IoError, ErrorKind, Write as IoWrite};
use std::path::Path;
use std::process::Command;
use tempfile::NamedTempFile;
Expand Down Expand Up @@ -51,6 +51,13 @@ pub fn run_print_schema<W: IoWrite>(
Ok(())
}

fn simplify_patch_error(err: IoError) -> Box<dyn Error> {
match err.kind() {
ErrorKind::NotFound => "Unable to find `patch` command, is it installed?".into(),
_ => err.into(),
}
}

pub fn output_schema(
database_url: &str,
config: &config::PrintSchema,
Expand Down Expand Up @@ -85,7 +92,8 @@ pub fn output_schema(
let output = Command::new("patch")
.arg(out_path)
.arg(patch_file)
.output()?;
.output()
.map_err(simplify_patch_error)?;
if !output.status.success() {
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
Expand Down