Repository: Shopify/shopify-cli (Ruby)

Issue:
[Bug]: Cannot log out when I am not authorized to edit themes
### Please confirm that you have:

- [X] Searched [existing issues](https://github.com/Shopify/shopify-cli/issues) to see if your issue is a duplicate. (If you’ve found a duplicate issue, feel free to add additional information in a comment on it.)
- [X] Reproduced the issue in [the latest CLI version](https://github.com/Shopify/shopify-cli/releases).

### What type of project are you working on?

theme

### Expected behavior

I still have issues with different types of accounts. Partner accounts, or development stores. Which means I have to log out a lot, to login again using a different account.

Usually, I could just log out and login again when I am using the wrong account to log in. 



### Actual behavior

Since the last update, I receive the attached error when running `shopify logout`

<img width="752" alt="Schermafbeelding 2022-04-12 om 11 16 45" src="https://user-images.githubusercontent.com/2357867/162926044-ae5c7cb9-1c66-4218-9f6d-a0f11599693c.png">

### Stack trace

_No response_

### Reproduction steps

1. Log in using a partner account that does not have rights to edit themes
2. Run shopify logout

### Operating System

macOS Monterey 12.1

### CLI version (run `shopify version` if you're not sure)

2.15.5

### Shell

zsh

### Ruby version (run `ruby -v` if you're not sure)

ruby 2.6.8p205

### What language and version are you using in your application?

_No response_


Discussion:
I had the same issu.

Could fixit with these steps on a Mac:
https://github.com/Shopify/shopify-cli/issues/2231#issuecomment-1093801788
def a bug, happening here as well. fix is to manually delete ~/.cache/shopify/.db_pstore and attempt logging in again.



I am having the same issue.

**Operating system**
macOS Monterey 12.3.1

**CLI version**
Shopify CLI 2.15.6

**Ruby version**
ruby 2.6.8p205



Why do we even get this error if we are authorized? This problem is following us from start. 
It should be fixed in v2.16.1. Sorry for the inconvenience!



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5558edbbfd..acf34fcd48 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h
 ## [Unreleased]
 
 ### Fixed
+* [#2279](https://github.com/Shopify/shopify-cli/pull/2279): Fix logout when there are theme permission issues
 * [#2285](https://github.com/Shopify/shopify-cli/pull/2285): Fix extension loading for extension connect
 
 ## Version 2.16.0 - 2022-04-25
diff --git a/lib/shopify_cli/commands/logout.rb b/lib/shopify_cli/commands/logout.rb
index e4256f76de..2eca812562 100644
--- a/lib/shopify_cli/commands/logout.rb
+++ b/lib/shopify_cli/commands/logout.rb
@@ -31,7 +31,7 @@ def try_delete_development_theme
         return unless has_shop?
 
         ShopifyCLI::Theme::DevelopmentTheme.delete(@ctx)
-      rescue ShopifyCLI::API::APIRequestError
+      rescue ShopifyCLI::API::APIRequestError, ShopifyCLI::Abort, ShopifyCLI::AbortSilent
         # Ignore since we can't delete it
       end
     end


Test patch:
diff --git a/test/shopify-cli/commands/logout_test.rb b/test/shopify-cli/commands/logout_test.rb
index f5cdee16ac..1d58b3abdf 100644
--- a/test/shopify-cli/commands/logout_test.rb
+++ b/test/shopify-cli/commands/logout_test.rb
@@ -1,4 +1,5 @@
 require "test_helper"
+require "shopify_cli/theme/development_theme"
 
 module ShopifyCLI
   module Commands
@@ -28,6 +29,15 @@ def test_call_deletes_db_keys_that_exist
         run_cmd("logout")
       end
 
+      def test_call_finishes_if_dev_theme_deletion_fails
+        ShopifyCLI::DB.expects(:exists?).with(:shop).twice.returns(true)
+        ShopifyCLI::DB.expects(:exists?).with(:organization_id).once.returns(true)
+        ShopifyCLI::Theme::DevelopmentTheme.expects(:delete).once.raises(ShopifyCLI::Abort)
+        @context.expects(:puts).with("Successfully logged out of your account")
+
+        run_cmd("logout")
+      end
+
       def test_help_argument_calls_help
         @context.expects(:puts).with(ShopifyCLI::Commands::Logout.help)
         run_cmd("help logout")