Skip to content

Conversation

iksuddle
Copy link

@iksuddle iksuddle commented Aug 9, 2025

Addresses Issue #2055 by updating .shuttle/config.toml as follows:

  • Removes id when a project is deleted using shuttle project delete
  • Inserts/updates id when a project is created using shuttle project create --name ...

This should prevent potential mismatches and provide a smoother user experience.

Copy link
Member

@jonaro00 jonaro00 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Unfortunately, there are many edge-cases that need to be considered. Leaving my thoughts:

}

self.ctx.set_project_id(project.id);
self.ctx.save_local_internal()?;
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 are calling project create (which can be called from any dir) from a directory without a rust project, this would write a .shuttle/config.toml file in a location where it is not wanted. We might need a way to save the config only if it existed when trying to load it.

let res = client.delete_project(pid).await?.into_inner();

self.ctx.remove_project_id();
self.ctx.save_local_internal()?;
Copy link
Member

Choose a reason for hiding this comment

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

If a --id different from the id in the config file is provided, we don't want to clear the id in the config file.

Copy link
Member

Choose a reason for hiding this comment

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

@iksuddle Your comment about return type on load_project_id seems to have disappeared for me... Here's my reply anyways:
Only knowing where the loaded id came from is not enough to know if an explicit --id arg is different from the one in the local_internal config file, so it seems like we need to know what was provided in both places.
Maybe adding a self.ctx.linked_project_id() -> Option<&str> (returning the id loaded from the file, if exists) and comparing it to the self.ctx.project_id() (the "resolved" id) will work?

The note about only doing it when the file exists is also valid. The method above could be used to know if the file exists, since the id is the only field in there. It could also be generalised to something like self.ctx.local_internal_exists() -> bool.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I deleted that comment when I realized it wouldn't work.

There seems to be some discrepancy between using --id vs --name.

Currently, if you run shuttle project delete --id 123 in a directory that is not a rust project, you get the error Failed to find a Rust project in this directory ... due to calling project_args.workspace_path() at the top of load_local_internal_config(). The error comes from cargo metadata. So you can't actually delete a project unless you're in a crate.

I'm not sure if this is the desired behavior, but using --name instead doesn't cause this error and results in Project with name '123' not found in your project list.

To be honest, I'm not sure why they are different, since in both load_local_internal_config and get_local_config have workspace_path().unwrap_or(...).

Also I was wondering what exactly should happen? Should both --id and --name delete projects, or neither, or just --name?

Copy link
Author

@iksuddle iksuddle Sep 11, 2025

Choose a reason for hiding this comment

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

Additionally, I believe project_create would need ctx.project to be Some (by calling load_project_id) so that the config file can be created/updated. This means adding it to the match for commands that require load_project_id.

Edit:
After looking into it some more I realized there's more to consider since the load_project_id function only creates a project for the deploy command, and it would be weird to create a project twice. So I guess we could either set ctx.project before calling save_local_internal in project_create, or change the way create_or_update_ignore_file works.

@iksuddle
Copy link
Author

iksuddle commented Sep 9, 2025

Thanks for all the feedback! I'll aim to fix everything you mentioned soon.


pub fn remove_project_id(&mut self) {
*self.project_internal.as_mut().unwrap().as_mut().unwrap() =
InternalProjectConfig { id: None };
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's better to modify the id field in place instead of replacing the config (in case more fields are added). Same is true for set_project_id

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.

2 participants