Skip to content

Commit

Permalink
fix asset error with there is no selected snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
bishoy-at-pieces committed Oct 10, 2024
1 parent 1c113d6 commit 53101c7
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 53101c7

Please sign in to comment.