diff --git a/compiler/crates/relay-bin/src/errors.rs b/compiler/crates/relay-bin/src/errors.rs index 7aa20884f1710..7fa03ad88dbea 100644 --- a/compiler/crates/relay-bin/src/errors.rs +++ b/compiler/crates/relay-bin/src/errors.rs @@ -18,6 +18,11 @@ pub enum Error { #[error("{0}")] ConfigError(relay_compiler::errors::Error), + #[error( + "{source}\n\nHint: You can dump the config JSON schema with:\n relay-compiler config-json-schema\n\nFor documentation, see:\n https://relay.dev/docs/getting-started/compiler-config/" + )] + ConfigErrorWithHint { source: Box }, + #[error("Unable to run relay compiler. Error details: \n{details}")] CompilerError { details: String }, diff --git a/compiler/crates/relay-bin/src/main.rs b/compiler/crates/relay-bin/src/main.rs index 0468c648409f2..7e6a9936c5dbc 100644 --- a/compiler/crates/relay-bin/src/main.rs +++ b/compiler/crates/relay-bin/src/main.rs @@ -278,11 +278,23 @@ async fn main() { } fn get_config(config_path: Option) -> Result { - match config_path { - Some(config_path) => Config::load(config_path).map_err(Error::ConfigError), - None => Config::search(¤t_dir().expect("Unable to get current working directory.")) - .map_err(Error::ConfigError), - } + let result = match config_path { + Some(config_path) => Config::load(config_path), + None => Config::search(¤t_dir().expect("Unable to get current working directory.")), + }; + result.map_err(|err| { + let is_config_error = matches!( + err, + CompilerError::ConfigError { .. } | CompilerError::ConfigFileValidation { .. } + ); + let mut err = Error::ConfigError(err); + if is_config_error { + err = Error::ConfigErrorWithHint { + source: Box::new(err), + }; + } + err + }) } fn configure_logger(output: OutputKind, terminal_mode: TerminalMode) {