Skip to content

Conversation

@KushalMeghani1644
Copy link
Contributor

This PR makes several critical improvements to the Tauri CLI to enhance stability, performance, and maintainability:

  1. Thread safety and resilience: The stdout/stderr reader threads now lock the mutex only per iteration, and poisoned locks are handled gracefully. This prevents deadlocks and panics when running commands concurrently, especially on long-running build processes.

  2. Performance and clarity: Command argument formatting was refactored from fold to join, reducing memory allocations and improving readability.

  3. Cross-platform safety: File extension parsing now correctly handles OsStr conversions, preventing potential panics or incorrect parsing on non-UTF-8 paths.

  4. Verbosity consistency: Introduced a helper function to centralize verbosity parsing from environment variables and CLI flags, ensuring predictable logging levels across all subcommands.

  5. Default values: Added Default derivations to config-related structs to make deserialization more robust and prevent unnecessary unwraps.

  6. Maintainability: Standardized error handling and logging formatting for clearer messages and easier future modifications.

  7. Regression safety: Added a minimal CLI help test to catch accidental changes to subcommand names or descriptions.

These changes are necessary to ensure the CLI behaves reliably under all conditions, handles errors gracefully, and remains maintainable as Tauri continues to grow.

- Ensure granular mutex locking in stdout/stderr threads to prevent deadlocks and panics.
- Handle poisoned locks gracefully to improve CLI resilience.
- Replace inefficient fold-based command argument formatting with join for better performance.
- Simplify file extension handling using and_then(|ext| ext.to_str()) for clarity and cross-platform safety.
- Introduce get_verbosity helper for consistent and maintainable verbosity handling.
- Add Default derives to configuration structs for safer deserialization.
- Add minimal CLI smoke test to catch regressions in subcommand help messages.
- Standardize and clean up logging and error handling for better maintainability.
@KushalMeghani1644 KushalMeghani1644 requested a review from a team as a code owner October 20, 2025 13:16
@github-project-automation github-project-automation bot moved this to 📬Proposal in Roadmap Oct 20, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2025

}

#[derive(Deserialize)]
#[derive(Deserialize, Default)]
Copy link
Member

Choose a reason for hiding this comment

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

Is that used anywhere? Same for PackageJson

err.format(&mut app)
}

fn get_verbosity(cli_verbose: u8) -> u8 {
Copy link
Member

Choose a reason for hiding this comment

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

Verbosity consistency: Introduced a helper function to centralize verbosity parsing from environment variables and CLI flags, ensuring predictable logging levels across all subcommands.

This function is only used once, where the code was inlined before. I don't mind having this in a separate function but wanted to mention this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this function because the logic may be reused (e.g. if we later need verbosity in other commands),
but I’m fine inlining it if preferred.

.get_args()
.map(|a| a.to_string_lossy())
.collect::<Vec<_>>()
.join(" ");
Copy link
Member

Choose a reason for hiding this comment

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

i wonder if that's slower than fold but i agree that it's easier on the eyes.

Comment on lines 189 to 192
///
/// The passed `bin_name` parameter should be how you want the help messages to display the command.
/// This defaults to `cargo-tauri`, but should be set to how the program was called, such as
/// `cargo tauri`.
Copy link
Member

Choose a reason for hiding this comment

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

Were these comments incorrect?

Comment on lines 358 to 360
if let Ok(mut lines) = stdout_lines_.lock() {
lines.extend(line.as_bytes());
}
Copy link
Member

Choose a reason for hiding this comment

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

i think we should keep the lock() where it was for performance reasons. the next time we will need a lock is after these threads are stopped.

}
}
Err(_) => (),
Err(_) => break,
Copy link
Member

Choose a reason for hiding this comment

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

probably not a good idea, just because one line may error out doesn't mean we should stop reading completely. Except of course if we've had issues with the old behavior which i'm not aware of.

Comment on lines 378 to 382
if let Ok(mut lines) = stderr_lines_.lock() {
lines.extend(line.as_bytes());
}
}
Err(_) => (),
Err(_) => break,
Copy link
Member

Choose a reason for hiding this comment

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

same

Comment on lines +419 to +423
#[test]
fn help_output_includes_build() {
let help = Cli::command().render_help().to_string();
assert!(help.contains("Build"));
}
Copy link
Member

Choose a reason for hiding this comment

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

i'm kinda failing to see the value of this test but it's not technically wrong so fair enough i guess

Comment on lines -79 to -83
// treat all other extensions as json
_ => Ok(Self(
// from tauri-utils/src/config/parse.rs:
// we also want to support **valid** json5 in the .json extension
// if the json5 is not valid the serde_json error for regular json will be returned.
Copy link
Member

Choose a reason for hiding this comment

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

since the logic is still the same we should probably keep the comments as well

Copy link
Member

Choose a reason for hiding this comment

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

@KushalMeghani1644 can you copy these comments over as well?

Copy link
Contributor Author

@KushalMeghani1644 KushalMeghani1644 Nov 5, 2025

Choose a reason for hiding this comment

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

Oh yes! I missed these! though Now I have added them back now. Sorry for the inconsistency

@KushalMeghani1644
Copy link
Contributor Author

Hey! @FabianLars I have made the changes, you reviewed/requested... I have added back the comments that I had blindly removed... removed the Default as-well. I hope the changes made are fine. :)

Copy link
Member

@FabianLars FabianLars left a comment

Choose a reason for hiding this comment

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

thanks :)

@FabianLars FabianLars merged commit d06a199 into tauri-apps:dev Nov 5, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from 📬Proposal to 🔎 In audit in Roadmap Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 In audit

Development

Successfully merging this pull request may close these issues.

2 participants