Skip to content

Conversation

@taearls
Copy link
Contributor

@taearls taearls commented Nov 8, 2025

Fixes #10754

This PR improves the user experience when running plugin add by automatically creating missing plugin config directories and providing clear, actionable error messages.

Changes

When running nushell from a terminal with a configuration file path to a location where no file exists:

Before

Running this command throws an unhelpful error:

XDG_CONFIG_HOME=/tmp/nu-test-config nu -c "plugin add nu_plugin_example"
# => × Not found
# =>   ╭─[source:1:1]
# => 1 │ plugin add nu_plugin_example
# =>   · ─────┬────
# =>   ·      ╰── Not found
# =>   ╰────
# =>  help: '/tmp/nu-test-config/nushell/plugin.msgpackz' does not exist

After

Running this command will succeed because the configuration file will be created automatically if it doesn't exist:

XDG_CONFIG_HOME=/tmp/nu-test-config nu -c "plugin add nu_plugin_example"
# no error thrown

Release Notes

Improved error messages when plugin config directory doesn't exist during plugin add. The command now automatically creates missing parent directories, aligning with behavior in other Nushell commands.

Tasks after submitting

taearls and others added 3 commits November 8, 2025 15:09
Fixes nushell#10754

When registering a plugin fails because the config directory doesn't exist
or isn't writable, the error message was unhelpful:
"Plugin failed to load: No such file or directory (os error 2)"

This change:
- Checks if the parent directory exists before creating the plugin registry file
- Automatically creates the directory if it's missing (like other Nu commands)
- Provides clear error messages using ErrorKind::DirectoryNotFound
- Shows the actual directory path that's problematic with helpful context

Now users see actionable errors that distinguish between:
- Plugin binary file not found
- Config directory doesn't exist or can't be created

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Apply cargo fmt formatting to multi-line nested imports.
- Collapse nested if statements using let-chain syntax
- Replace useless format!() with .to_string()
@taearls taearls changed the title fix: improve error messages when plugin config directory doesn't exist fix: improve error message when plugin add fails because config directory doesn't exist (issue #10754) Nov 8, 2025
@taearls taearls changed the title fix: improve error message when plugin add fails because config directory doesn't exist (issue #10754) Improve error message when plugin add fails because config directory doesn't exist (Issue #10754) Nov 8, 2025
@taearls taearls marked this pull request as ready for review November 8, 2025 22:08
@taearls
Copy link
Contributor Author

taearls commented Nov 8, 2025

Hi! This is my first time contributing. I did my best to follow the contribution guidelines. Since this is such a small bug fix, I'm not sure if this change warrants updating documentation, but I left the task in the PR description for now. Let me know if you'd like me to update it!

Copy link
Contributor

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

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

Hi, thank you for your contribution, the code looks good to me.
Can you add a test for the behavior? You can add it to tests/plugins/registry_file.rs.

@taearls
Copy link
Contributor Author

taearls commented Nov 14, 2025

Hi, thank you for your contribution, the code looks good to me. Can you add a test for the behavior? You can add it to tests/plugins/registry_file.rs.

Done! Thanks for the feedback.

@taearls taearls requested a review from WindSoilder November 14, 2025 18:23
Copy link
Contributor

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

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

Thanks!

@WindSoilder
Copy link
Contributor

The CI failed, can you run cargo fmt first?

@taearls
Copy link
Contributor Author

taearls commented Nov 16, 2025

The CI failed, can you run cargo fmt first?

Done. Sorry about that!

@cptpiepmatz cptpiepmatz self-requested a review November 16, 2025 21:58
Copy link
Member

@cptpiepmatz cptpiepmatz left a comment

Choose a reason for hiding this comment

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

Thank you, I have some nitpicks. You don't have to do them if you don't want to or think they are good as they are.

// Save the modified file on success
// First, ensure the parent directory exists
if let Some(parent_dir) = plugin_registry_file_path.parent()
&& !parent_dir.exists()
Copy link
Member

Choose a reason for hiding this comment

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

This is a nitpick but you don't have to do this check, just run the fs::create_dir_all, it already checks if the necessary dirs exist.

file_span,
parent_dir.to_path_buf(),
"Cannot create plugin config directory. \
Ensure the parent path is accessible and you have write permissions"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you have to write this long context. If you don't have the permissions to create such a dir, you already get a permissions denied error, making this very obvious. Very long messages in our messages get somewhat messy. You don't have to remove that, just wanna say. You can take a look how it looks in your terminal.

@cptpiepmatz
Copy link
Member

Can you add a before and after to the changelog. That would make it easier to see what you did when reading the changelog. You can do it similar to this: #16892

@taearls
Copy link
Contributor Author

taearls commented Nov 16, 2025

Thank you, I have some nitpicks. You don't have to do them if you don't want to or think they are good as they are.

Thanks for the feedback! I appreciate your suggestions. I don't want to add anything unnecessary, so I'm happy to clean that up.

I'll also work on adding a clear before / after change log.

@taearls
Copy link
Contributor Author

taearls commented Nov 18, 2025

@cptpiepmatz I applied changes in response to your feedback and updated the PR description with a before / after changelog. Please let me know if there's anything else you think could be improved!

@cptpiepmatz
Copy link
Member

Thank you for your changes but this is not really what I asked for, sorry. The changelog is mainly for nushell users not developers. So I expected a terminal output, what you would see as a nushell user.

@taearls
Copy link
Contributor Author

taearls commented Nov 18, 2025

Thank you for your changes but this is not really what I asked for, sorry. The changelog is mainly for nushell users not developers. So I expected a terminal output, what you would see as a nushell user.

Oh got it. Sorry about that, I misunderstood. I'll update that.

@taearls
Copy link
Contributor Author

taearls commented Nov 18, 2025

updated the changelog!

I wasn't 100% sure about including the XDG_CONFIG_HOME=/tmp/nu-test-config aspect of the command because I'm not sure how often users are setting that environment variable when executing nushell from the command line. I decided to include it because it was the easiest way I could find to succinctly demonstrate the behavior before and after the changes.

let me know if you have any feedback @cptpiepmatz

Copy link
Member

@cptpiepmatz cptpiepmatz left a comment

Choose a reason for hiding this comment

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

Thank you, I like that. Let's wait for the pipeline and then we can merge. ❤️

@cptpiepmatz cptpiepmatz merged commit c854944 into nushell:main Nov 18, 2025
16 checks passed
@github-actions github-actions bot added this to the v0.109.0 milestone Nov 18, 2025
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.

Unhelpful error message registering a plugin when unable to write to config directory

3 participants