Skip to content

Commit

Permalink
idl: Log output with ANCHOR_LOG on failure and improve build error …
Browse files Browse the repository at this point in the history
…message (#3284)
  • Loading branch information
acheroncrypto authored Sep 27, 2024
1 parent cf81636 commit c960b8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- idl: Fix using full path types with `Program` ([#3228](https://github.com/coral-xyz/anchor/pull/3228)).
- lang: Use closures for `init` constraints to reduce the stack usage of `try_accounts` ([#2939](https://github.com/coral-xyz/anchor/pull/2939)).
- lang: Allow the `cfg` attribute above the instructions ([#2339](https://github.com/coral-xyz/anchor/pull/2339)).
- idl: Log output with `ANCHOR_LOG` on failure and improve build error message ([#3284](https://github.com/coral-xyz/anchor/pull/3284)).

### Breaking

Expand Down
17 changes: 10 additions & 7 deletions idl/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,16 @@ fn build(
.current_dir(program_path)
.stderr(Stdio::inherit())
.output()?;

let stdout = String::from_utf8_lossy(&output.stdout);
if env::var("ANCHOR_LOG").is_ok() {
eprintln!("{}", stdout);
}

if !output.status.success() {
return Err(anyhow!("Building IDL failed"));
return Err(anyhow!(
"Building IDL failed. Run `ANCHOR_LOG=true anchor idl build` to see the logs."
));
}

enum State {
Expand All @@ -191,13 +199,8 @@ fn build(
let mut types = BTreeMap::new();
let mut idl: Option<Idl> = None;

let output = String::from_utf8_lossy(&output.stdout);
if env::var("ANCHOR_LOG").is_ok() {
println!("{}", output);
}

let mut state = State::Pass;
for line in output.lines() {
for line in stdout.lines() {
match &mut state {
State::Pass => match line {
"--- IDL begin address ---" => state = State::Address,
Expand Down

0 comments on commit c960b8c

Please sign in to comment.