Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: turbo info command for debugging #9368

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

feat: turbo info command for debugging #9368

wants to merge 6 commits into from

Conversation

anthonyshew
Copy link
Contributor

@anthonyshew anthonyshew commented Nov 1, 2024

Description

A command to provide debugging information for reproductions or otherwise understand a machine better. Output will look something close to this.

CLI:
   Version: 2.2.4-canary.4
   Location: /Users/anthonyshew/projects/open/turbo/target/debug/turbo
   Daemon status: Running
   Package manager: pnpm

Platform:
   Architecture: aarch64
   Operating system: macos
   Available memory (MB): 13598
   Available CPU cores: 10

Environment:
   CI: None
   Terminal (TERM): xterm-256color
   Terminal program (TERM_PROGRAM): tmux
   Terminal program version (TERM_PROGRAM_VERSION): 3.4
   Shell (SHELL): /bin/zsh
   stdin: false

Turborepo System Environment Variables:
   TURBO_INVOCATION_DIR: /Users/anthonyshew/projects/open/turbo

Testing Instructions

Try it out!

Copy link

vercel bot commented Nov 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 4, 2024 7:45pm
8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 7:45pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 7:45pm
examples-gatsby-web ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 7:45pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 7:45pm
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 7:45pm
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 7:45pm
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 7:45pm
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview Nov 4, 2024 7:45pm

@anthonyshew anthonyshew changed the title feat: turbo info command for debugging feat: turbo info command for debugging Nov 1, 2024
@@ -475,9 +475,7 @@ impl Args {
}
}

/// Defines the subcommands for CLI. NOTE: If we change the commands in Go,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but saw it mentioning Go so ✂️

Copy link
Contributor

@NicholasLYang NicholasLYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a couple notes

crates/turborepo-lib/src/cli/mod.rs Outdated Show resolved Hide resolved
Comment on lines +25 to +33
let package_manager = match PackageJson::load(&base.repo_root.join_component("package.json")) {
Ok(package_json) => {
match PackageManager::read_or_detect_package_manager(&package_json, &base.repo_root) {
Ok(pm) => pm.to_string(),
Err(_) => "Not found".to_owned(),
}
}
Err(_) => "Not found".to_owned(),
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some Rust code golf. I'd recommend manually committing this because Rustfmt will probably disagree with this formatting

Suggested change
let package_manager = match PackageJson::load(&base.repo_root.join_component("package.json")) {
Ok(package_json) => {
match PackageManager::read_or_detect_package_manager(&package_json, &base.repo_root) {
Ok(pm) => pm.to_string(),
Err(_) => "Not found".to_owned(),
}
}
Err(_) => "Not found".to_owned(),
};
let package_manager = PackageJson::load(&base.repo_root.join_component("package.json"))
.and_then(|package_json| PackageManager::read_or_detect_package_manager(&package_json, &base.repo_root))
.map_or_else(|_| "Not found".to_owned(), |pm| pm.to_string());

Comment on lines +1223 to +1226
match info::run(base).await {
Ok(()) => {}
Err(_e) => panic!("`info` command failed."),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally want to avoid panic here and if we do panic, we should make sure to include the underlying error.

You can use ? operator here to bubble up the error if you add a new variant to the cli error type here:

#[error(transparent)]
Info(#[from] info::Error),
Suggested change
match info::run(base).await {
Ok(()) => {}
Err(_e) => panic!("`info` command failed."),
}
info::run(base).await?;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I recommended panic here because the previous message was to open a GitHub Issue and panic includes that advice

NoCurrentExe(#[from] io::Error),
}

pub async fn run(base: CommandBase) -> Result<(), Error> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ITG (non blocking follow up): Separate the data from the display logic to make this more unit-test friendly and support additional output formats like JSON.

Something like:

struct TurboInfo {
    package_manager: String,
    daemon_status: String,
    ...
}

And then have turbo_info.print() to actually write the data to stdout

if key == "TURBO_TEAM"
|| key == "TURBO_TEAMID"
|| key == "TURBO_TOKEN"
|| key == "TURBO_API"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're considering TURBO_API to be sensitive, we should also consider TURBO_LOGIN to be sensitive.

println!("Turborepo System Environment Variables:");
for (key, value) in env::vars() {
// Don't print sensitive information
if key == "TURBO_TEAM"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TURBO_REMOTE_CACHE_SIGNATURE_KEY should be added to this list of sensitive keys

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should make this opt-in instead of opt-out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants