tilmanginzel / alfred-bluetooth-workflow

Yet another Alfred workflow to connect / disconnect Bluetooth devices
MIT License
189 stars 8 forks source link

workflow update fails #20

Closed cameronsstone closed 3 years ago

cameronsstone commented 3 years ago

Update fails for me from both alfred invocation and terminal (user and workflow ID anonymized):

❯ /usr/bin/python alfred_bluetooth_workflow.py workflow:update
.
14:23:09 workflow.py:2334 INFO     checking for update ...
.
14:23:09 update.py:312 INFO     retrieving releases: tilmanginzel/alfred-bluetooth-workflow
14:23:09 workflow.py:2074 ERROR    'NoneType' object has no attribute 'read'
Traceback (most recent call last):
  File "/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows/user.workflow.<workflow-id>/workflow/workflow.py", line 2067, in run
    func(self)
  File "alfred_bluetooth_workflow.py", line 39, in main
    query = wf.args[0] if len(wf.args) else None
  File "/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows/user.workflow.<workflow-id>/workflow/workflow.py", line 1213, in args
    msg = self.magic_arguments[name]()
  File "/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows/user.workflow.<workflow-id>/workflow/workflow.py", line 2552, in do_update
    if self.start_update():
  File "/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows/user.workflow.<workflow-id>/workflow/workflow.py", line 2359, in start_update
    if not update.check_update(github_slug, version, self.prereleases):
  File "/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows/user.workflow.<workflow-id>/workflow/update.py", line 348, in check_update
    releases = get_valid_releases(github_slug, prereleases)
  File "/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows/user.workflow.<workflow-id>/workflow/update.py", line 316, in get_valid_releases
    for release in wf().cached_data('gh-releases-' + slug, retrieve_releases):
  File "/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows/user.workflow.<workflow-id>/workflow/workflow.py", line 1695, in cached_data
    data = data_func()
  File "/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows/user.workflow.<workflow-id>/workflow/update.py", line 313, in retrieve_releases
    return web.get(api_url).json()
  File "/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows/user.workflow.<workflow-id>/workflow/web.py", line 271, in json
    return json.loads(self.content, self.encoding or 'utf-8')
  File "/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows/user.workflow.<workflow-id>/workflow/web.py", line 302, in content
    self._content = self.raw.read()

I'm using workflow version 0.9.0 with Alfred 4.3. Any ideas?

cameronsstone commented 3 years ago

So calling blt workflow:autoupdate caused a successful reinstall, and has made the "new version available" entry go away, but it seems to have just installed version 0.9.0 again. Also, now I can't run any blt workflow:* commands from Alfred anymore. However, I can run /usr/bin/python alfred_bluetooth_workflow.py workflow:noautoupdate from the commandline, so I think I've managed to disable autoupdate again.

I can now run /usr/bin/python alfred_bluetooth_workflow.py workflow:update from the commandline, so that's good, but it keeps prompting to reinstall 0.9.0 over and over again, so there's still something messed up.

cameronsstone commented 3 years ago

I tried a remove, then reinstall, and ended up in the same state (workflow working, but Dean's workflow magic commands are not).

tilmanginzel commented 3 years ago

Hi @cameronsstone, thanks for reporting. I will try to take a look at it this coming weekend! (cc @trietsch)

tilmanginzel commented 3 years ago

Hi again, I can only partially reproduce the issue (Alfred 4.3, Workflow 0.9.0, MacOS 10.15.7). Calling

/usr/bin/python alfred_bluetooth_workflow.py workflow:update

produces the same output you get, but I am also not sure if this would be a valid way to trigger the update. Using blt workflow:update gives the expected output for me.

Can you please check the following:

This is the output I get:

17:49:10 workflow.py:2055 DEBUG    ---------- Bluetooth Connector (0.9.0) ----------
17:49:10 workflow.py:1462 DEBUG    reading settings from /Users/<user>/Library/Application Support/Alfred/Workflow Data/de.tilmanginzel.alfred.bluetooth/settings.json
17:49:10 workflow.py:2311 DEBUG    Auto update turned off by user
17:49:10 workflow.py:1689 DEBUG    loading cached data: /Users/<user>/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/de.tilmanginzel.alfred.bluetooth/__workflow_update_status.cpickle
17:49:10 workflow.py:2269 DEBUG    update_data: {u'available': False}
17:49:10 update.py:308 DEBUG    retrieving releases list: https://api.github.com/repos/tilmanginzel/alfred-bluetooth-workflow/releases
17:49:10 workflow.py:1689 DEBUG    loading cached data: /Users/<user>/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/de.tilmanginzel.alfred.bluetooth/gh-releases-tilmanginzel-alfred-bluetooth-workflow.cpickle
17:49:10 update.py:280 DEBUG    release v0.9.0: https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.9.0/Bluetooth.Connector.alfredworkflow
17:49:10 update.py:327 DEBUG    release: {u'version': u'v0.9.0', u'prerelease': False, u'download_url': u'https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.9.0/Bluetooth.Connector.alfredworkflow'}
17:49:10 update.py:280 DEBUG    release v0.8.0: https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.8.0/Bluetooth.Connector.alfredworkflow
17:49:10 update.py:327 DEBUG    release: {u'version': u'v0.8.0', u'prerelease': False, u'download_url': u'https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.8.0/Bluetooth.Connector.alfredworkflow'}
17:49:10 update.py:280 DEBUG    release v0.7.0: https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.7.0/Bluetooth.Connector.alfredworkflow
17:49:10 update.py:327 DEBUG    release: {u'version': u'v0.7.0', u'prerelease': False, u'download_url': u'https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.7.0/Bluetooth.Connector.alfredworkflow'}
17:49:10 update.py:280 DEBUG    release v0.6.0: https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.6.0/Bluetooth.Connector.alfredworkflow
17:49:10 update.py:327 DEBUG    release: {u'version': u'v0.6.0', u'prerelease': False, u'download_url': u'https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.6.0/Bluetooth.Connector.alfredworkflow'}
17:49:10 update.py:280 DEBUG    release v0.5.0: https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.5.0/Bluetooth.Connector.alfredworkflow
17:49:10 update.py:327 DEBUG    release: {u'version': u'v0.5.0', u'prerelease': False, u'download_url': u'https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.5.0/Bluetooth.Connector.alfredworkflow'}
17:49:10 update.py:280 DEBUG    release v0.4.0: https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.4.0/Bluetooth.Connector.alfredworkflow
17:49:10 update.py:327 DEBUG    release: {u'version': u'v0.4.0', u'prerelease': False, u'download_url': u'https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.4.0/Bluetooth.Connector.alfredworkflow'}
17:49:10 update.py:280 DEBUG    release v0.3.0: https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.3.0/Bluetooth.Connector.alfredworkflow
17:49:10 update.py:327 DEBUG    release: {u'version': u'v0.3.0', u'prerelease': False, u'download_url': u'https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.3.0/Bluetooth.Connector.alfredworkflow'}
17:49:10 update.py:280 DEBUG    release v0.2.0: https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.2.0/Bluetooth.Connector.alfredworkflow
17:49:10 update.py:327 DEBUG    release: {u'version': u'v0.2.0', u'prerelease': False, u'download_url': u'https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.2.0/Bluetooth.Connector.alfredworkflow'}
17:49:10 update.py:280 DEBUG    release v0.1.0: https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.1.0/Bluetooth.Connector.alfredworkflow
17:49:10 update.py:327 DEBUG    release: {u'version': u'v0.1.0', u'prerelease': False, u'download_url': u'https://github.com/tilmanginzel/alfred-bluetooth-workflow/releases/download/v0.1.0/Bluetooth.Connector.alfredworkflow'}
17:49:10 update.py:355 INFO     9 releases for tilmanginzel/alfred-bluetooth-workflow
17:49:10 update.py:363 DEBUG    latest=Version('0.9.0'), installed=Version('0.9.0')
17:49:10 workflow.py:1724 DEBUG    cached data: /Users/<user>/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/de.tilmanginzel.alfred.bluetooth/__workflow_update_status.cpickle
17:49:10 workflow.py:1216 DEBUG    No update available
17:49:10 workflow.py:2097 DEBUG    ---------- finished in 0.033s ----------
[17:49:10.735] Bluetooth Connector[Script Filter] {"items": [{"valid": false, "subtitle": "", "icon": {"path": "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns"}, "title": "No update available"}]}

Is there some suspicious output when you do this? It also seems like some data is read from a cache and a settings.json. This is currently in my settings.json:

> cat "/Users/<user>/Library/Application Support/Alfred/Workflow Data/de.tilmanginzel.alfred.bluetooth/settings.json"

{
  "__workflow_autoupdate": false,
  "__workflow_last_version": "0.9.0"
}

Can you please try to remove the cache and settings file (I just did this and they will be created again on next usage):

rm -rf "/Users/<user>/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/de.tilmanginzel.alfred.bluetooth"
rm -rf "/Users/<user>/Library/Application Support/Alfred/Workflow Data/de.tilmanginzel.alfred.bluetooth/settings.json"
cameronsstone commented 3 years ago

Thanks for looking into it.

I tried deleting those files and after next run the __workflow_last_version is 0.3.0. Trawling through Deanishe's workflow code, the alfred_env method in workflow.py is finding an environment variable called alfred_workflow_version with value 0.3.0. I don't have the faintest idea where that comes from, but it stops Dean's code from picking up the version from your version file, and means that the workflow never realizes it's real version and continually prompts to download the "updated" version.

A workaround is to set the version number in the info.plist instead. Add the following to the top-level <dict>:

    <key>version</key>
    <string>0.9.0</string>

I also figured out that workflow:magic seems to be broken in Dean's code. It has a call to send_feedback in list_magic, but doesn't call sys.exit, so there are two calls to send_feedback - that one, plus the one in your code. I'll file an issue in his project for that.

tilmanginzel commented 3 years ago

Trawling through Deanishe's workflow code, the alfred_env method in workflow.py is finding an environment variable called alfred_workflow_version. [...] I don't have the faintest idea where that comes from

Interesting, I also don't have an idea where this might come from, but I never really looked too much at the workflow.py code. The only thing I also noted in your filed issue is this path:

/Users/<user-id>/Documents/Backups/Alfred.alfredpreferences/workflows

Is this Backups folder a folder where all your workflows reside, or was this only a temporary one? Might be related, not sure...

What is your proposal on how we should proceed with this issue? So far I have not yet seen that this occurred for someone else, and it's a bit difficult for me to reproduce it unfortunately. We can leave it open for a while if you like, maybe someone finds a proper root cause and fix for it.

cameronsstone commented 3 years ago

The Backups path is just where all my workflows are, so they get backed up. I don't think that is the cause, but I could be wrong.

As for what to do, and given the lack of impact, I suggest one of:

  1. Hang back and see what Dean says in issue #170
  2. Switch from using a version file to using a version key-value pair in info.plist. I think Dean's worflow code should handle the migration transparently.
tilmanginzel commented 3 years ago

Switch from using a version file to using a version key-value pair in info.plist. I think Dean's worflow code should handle the migration transparently

That sounds like a good workaround, thanks for the hint. I will keep this open until a new version will be released so I don't forget about it. :)

tilmanginzel commented 3 years ago

I have added the version to info.plist and tested on a separate device that the update from 0.9.0 to 0.10.0 worked as expected. 👍