Content-Length: 272992 | pFad | https://github.com/starship/starship/pull/5000

8E fix(config): Handle invalid config file by Ceres445 · Pull Request #5000 · starship/starship · GitHub
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

fix(config): Handle invalid config file #5000

Closed
wants to merge 1 commit into from

Conversation

Ceres445
Copy link

@Ceres445 Ceres445 commented Mar 15, 2023

Description

Changed the default value for StarshipConfig to prevent crashing when invalid config path is provided.

Added a specific error message when invalid config path is provided.

Motivation and Context

Closes #4958
Closes #5001

How Has This Been Tested?

  • I have tested using MacOS
  • I have tested using Linux
  • I have tested using Windows

Checklist:

  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

Sorry, something went wrong.

Changed default for StarshipConfig to prevent crashing when invalid
config path is provided.

Added specific error message when invalid config path is provided.
@@ -149,19 +157,21 @@ impl StarshipConfig {
fn config_from_file() -> Option<toml::Table> {
let file_path = get_config_path()?;

let toml_content = match utils::read_file(file_path) {
let toml_content = match utils::read_file(&file_path) {
Copy link
Author

Choose a reason for hiding this comment

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

Changed the move to a borrow so I can use the file_path for the error message later. Worked in my testing, but I'm not sure if it will break in other cases.

Ok(content) => {
log::trace!("Config file content: \"\n{}\"", &content);
Some(content)
}
Err(e) => {
let level = if e.kind() == ErrorKind::NotFound {
log::Level::Debug
if e.kind() == ErrorKind::NotFound {
Copy link
Contributor

@domsleee domsleee Mar 15, 2023

Choose a reason for hiding this comment

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

I think this is inconsistent with prompt behaviour
When an invalid environment variable is specified, starship currently uses the default config (even if ~/.config/starship.config exists it seems)
If we want an error like this, I think it should be in the prompt as well, I feel like the user would expect print-config to print the configuration that is being used by the prompt?
I also have a PR on this issue, my bad: #5001

@andytom andytom changed the title Handle invalid config file fix(config): Handle invalid config file Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

starship print-config panics without a configuration file
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/starship/starship/pull/5000

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy