Skip to content

Commit

Permalink
Merge pull request #190 from pieces-app/fix-assets
Browse files Browse the repository at this point in the history
fix asset error with there is no selected snippet
  • Loading branch information
bishoy-at-pieces authored Oct 18, 2024
2 parents e0c97b5 + 53b0a6a commit 7239c65
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/pieces/commands/assets_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pygments.lexers import get_lexer_by_name, guess_lexer
from pygments.formatters import TerminalFormatter

from pieces_os_client.exceptions import NotFoundException

def check_assets_existence(func):
"""Decorator to ensure user has assets."""
Expand All @@ -30,13 +31,14 @@ def check_asset_selected(func):
If valid id it returns the asset_data to the called function.
"""
def wrapper(*args, **kwargs):
if AssetsCommands.current_asset is None:
return show_error("No asset selected.", "Please open an asset first using pieces open.")
from pieces.commands.list_command import ListCommand
try:
if AssetsCommands.current_asset is None:
raise ValueError("No asset selected")
AssetsCommands.current_asset.asset # Check if the current asset is vaild
except:
except (ValueError, NotFoundException):
# The selected asset is deleted
return show_error("Error occured in the command", "Please make sure the selected asset is valid.")
return ListCommand.list_assets()
return func(asset=AssetsCommands.current_asset,*args, **kwargs)
return wrapper

Expand Down

0 comments on commit 7239c65

Please sign in to comment.