Skip to content

Commit

Permalink
Add error messages for missing language option in SingleProjectConfig
Browse files Browse the repository at this point in the history
Summary: Add a better error message for the single project config for a missing "language" option.

Reviewed By: josephsavona

Differential Revision: D35058114

fbshipit-source-id: a9b771eaa9bb73bec23fa33adcc87c5f6d7e16ab
  • Loading branch information
alunyov authored and facebook-github-bot committed Mar 23, 2022
1 parent 3de455f commit 44d6887
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
10 changes: 8 additions & 2 deletions compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ impl Default for SingleProjectConfigFile {
excludes: get_default_excludes(),
schema_extensions: vec![],
no_future_proof_enums: false,
language: Some(TypegenLanguage::default()),
language: None,
custom_scalars: Default::default(),
schema_config: Default::default(),
eager_es_modules: false,
Expand Down Expand Up @@ -734,6 +734,12 @@ impl SingleProjectConfigFile {
}
})?;

let language = self.language.ok_or_else(||
Error::ConfigError {
details: "The `language` option is missing in the Relay configuration file. Please, specify one of the following options: \"language\": \"javascript\", \"language\": \"typescript\", or \"language\": \"flow\".".to_string(),
}
)?;

let project_config = ConfigFileProject {
output: self.artifact_directory.map(|dir| {
normalize_path_from_config(current_dir.clone(), common_root_dir.clone(), dir)
Expand All @@ -757,7 +763,7 @@ impl SingleProjectConfigFile {
.collect(),
persist: self.persist_config,
typegen_config: TypegenConfig {
language: self.language.unwrap_or_default(),
language,
custom_scalar_types: self.custom_scalars.clone(),
eager_es_modules: self.eager_es_modules,
flow_typegen: FlowTypegenConfig {
Expand Down
3 changes: 3 additions & 0 deletions compiler/crates/relay-compiler/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub enum Error {
source: serde_json::Error,
},

#[error("Unable to initialize relay compiler configuration. Error details: \n{details}")]
ConfigError { details: String },

#[error(
"Config `{config_path}` is invalid:{}",
validation_errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ fragment refetchableFragmentWithConnectionEsModules_PaginationFragment on Node

%project_config%
{
"eagerEsModules": true
"eagerEsModules": true,
"language": "flow"
}
==================================== OUTPUT ===================================
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ fragment refetchableFragmentWithConnectionEsModules_PaginationFragment on Node

%project_config%
{
"eagerEsModules": true
"eagerEsModules": true,
"language": "flow"
}
1 change: 0 additions & 1 deletion compiler/crates/relay-config/src/typegen_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ impl Default for TypegenLanguage {
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct TypegenConfig {
/// The desired output language, "flow" or "typescript".
#[serde(default)]
pub language: TypegenLanguage,

/// # For Flow type generation
Expand Down

0 comments on commit 44d6887

Please sign in to comment.