Skip to content

Commit

Permalink
Don't print "default" project name in diagnostics
Browse files Browse the repository at this point in the history
Reviewed By: alunyov

Differential Revision: D39331366

fbshipit-source-id: cf3b9a3aa97770b93a3193103f5fef03713b1a51
  • Loading branch information
captbaritone authored and facebook-github-bot committed Sep 8, 2022
1 parent 3b40fe5 commit 44fe2bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
10 changes: 9 additions & 1 deletion compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ Example file:
let mut hash = Sha1::new();
serde_json::to_writer(&mut hash, &config_file).unwrap();

let is_multi_project = match config_file {
ConfigFile::MultiProject(_) => true,
ConfigFile::SingleProject(_) => false,
};

let config_file = match config_file {
ConfigFile::MultiProject(config) => *config,
ConfigFile::SingleProject(config) => {
Expand Down Expand Up @@ -373,7 +378,10 @@ Example file:
let config = Self {
name: config_file.name,
artifact_writer: Box::new(ArtifactFileWriter::new(None, root_dir.clone())),
status_reporter: Box::new(ConsoleStatusReporter::new(root_dir.clone())),
status_reporter: Box::new(ConsoleStatusReporter::new(
root_dir.clone(),
is_multi_project,
)),
root_dir,
sources: config_file.sources,
excludes: config_file.excludes,
Expand Down
24 changes: 20 additions & 4 deletions compiler/crates/relay-compiler/src/status_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ pub trait StatusReporter {
pub struct ConsoleStatusReporter {
source_reader: Box<dyn SourceReader + Send + Sync>,
root_dir: PathBuf,
is_multi_project: bool,
}

impl ConsoleStatusReporter {
pub fn new(root_dir: PathBuf) -> Self {
pub fn new(root_dir: PathBuf, is_multi_project: bool) -> Self {
Self {
root_dir,
source_reader: Box::new(FsSourceReader),
is_multi_project,
}
}
}
Expand Down Expand Up @@ -87,9 +89,19 @@ impl ConsoleStatusReporter {
let output = self.print_diagnostic(diagnostic);
let formatted_output = match diagnostic.severity() {
DiagnosticSeverity::ERROR => {
format!("Error in the project `{}`: {}", project_name, output)
if self.is_multi_project {
format!("Error in the project `{}`: {}", project_name, output)
} else {
format!("Error: {}", output)
}
}
_ => {
if self.is_multi_project {
format!("In the project `{}`: {}", project_name, output)
} else {
output
}
}
_ => format!("In the project `{}`: {}", project_name, output),
};

(diagnostic.severity(), formatted_output)
Expand All @@ -101,7 +113,11 @@ impl ConsoleStatusReporter {
project_name,
} => {
for error in errors {
error!("Error in the project `{}`: {}", project_name, error);
if self.is_multi_project {
error!("Error in the project `{}`: {}", project_name, error);
} else {
error!("Error: {}", error);
}
}
}
_ => {
Expand Down

0 comments on commit 44fe2bc

Please sign in to comment.