Comfy-Org / comfy-cli

Command Line Interface for Managing ComfyUI
https://comfydocs.org/comfy-cli/getting-started
GNU General Public License v3.0
123 stars 15 forks source link

Crashed when `comfy model download` with unknown source #86

Closed snomiao closed 1 month ago

snomiao commented 1 month ago

Describe the bug

Crashed when comfy model download with unknown source url.

this is because of given default local_filename = None

image

when the url source is not recognized by any of huggingface_url or civitai url will fall into unknown source case,

image

and then pass into fn as ui.prompt(..., default=None), lead to this error

image

To Reproduce

comfy model download --url https://comfy-dl.vercel.app/sd_xl_refiner_1.0.safetensors

Expected behavior

No crash.

Nice to have

Additional context

C:\Users\snomi\comfy-cli>git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.

C:\Users\snomi\comfy-cli>
C:\Users\snomi\comfy-cli>comfy model download --url https://comfy-dl.vercel.app/sd_xl_refiner_1.0.safetensors
Model source is unknown
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ C:\Users\snomi\comfy-cli\comfy_cli\tracking.py:88 in wrapper                                     │
│                                                                                                  │
│    85 │   │   │   )                                                                              │
│    86 │   │   │   track_event(command_name, properties=filtered_kwargs)                          │
│    87 │   │   │                                                                                  │
│ ❱  88 │   │   │   return func(*args, **kwargs)                                                   │
│    89 │   │                                                                                      │
│    90 │   │   return wrapper                                                                     │
│    91                                                                                            │
│                                                                                                  │
│ ╭───────────────────────────────────────── locals ──────────────────────────────────────────╮    │
│ │            args = ()                                                                      │    │
│ │    command_name = 'model:download'                                                        │    │
│ │ filtered_kwargs = {                                                                       │    │
│ │                   │   '_ctx': <click.core.Context object at 0x00000267CF4BE7B0>,          │    │
│ │                   │   'url': 'https://comfy-dl.vercel.app/sd_xl_refiner_1.0.safetensors', │    │
│ │                   │   'relative_path': None,                                              │    │
│ │                   │   'set_civitai_api_token': None,                                      │    │
│ │                   │   'cli_version': '0.0.0',                                             │    │
│ │                   │   'tracing_id': '40359771-1a5f-4aae-9fa7-7379250fb4ea'                │    │
│ │                   }                                                                       │    │
│ │            func = <function download at 0x00000267CF47DB20>                               │    │
│ │          kwargs = {                                                                       │    │
│ │                   │   '_ctx': <click.core.Context object at 0x00000267CF4BE7B0>,          │    │
│ │                   │   'url': 'https://comfy-dl.vercel.app/sd_xl_refiner_1.0.safetensors', │    │
│ │                   │   'relative_path': None,                                              │    │
│ │                   │   'set_civitai_api_token': None                                       │    │
│ │                   }                                                                       │    │
│ │     sub_command = 'model'                                                                 │    │
│ ╰───────────────────────────────────────────────────────────────────────────────────────────╯    │
│                                                                                                  │
│ C:\Users\snomi\comfy-cli\comfy_cli\command\models\models.py:233 in download                      │
│                                                                                                  │
│   230 │   else:                                                                                  │
│   231 │   │   print("Model source is unknown")                                                   │
│   232 │                                                                                          │
│ ❱ 233 │   local_filename = ui.prompt_input(                                                      │
│   234 │   │   "Enter filename to save model as", default=local_filename                          │
│   235 │   )                                                                                      │
│   236                                                                                            │
│                                                                                                  │
│ ╭────────────────────────────────────── locals ───────────────────────────────────────╮          │
│ │                  _ctx = <click.core.Context object at 0x00000267CF4BE7B0>           │          │
│ │     civitai_api_token = None                                                        │          │
│ │               headers = None                                                        │          │
│ │    is_civitai_api_url = False                                                       │          │
│ │  is_civitai_model_url = False                                                       │          │
│ │        is_huggingface = False                                                       │          │
│ │        local_filename = None                                                        │          │
│ │              model_id = None                                                        │          │
│ │         relative_path = None                                                        │          │
│ │ set_civitai_api_token = None                                                        │          │
│ │                   url = 'https://comfy-dl.vercel.app/sd_xl_refiner_1.0.safetensors' │          │
│ │            version_id = None                                                        │          │
│ ╰─────────────────────────────────────────────────────────────────────────────────────╯          │
│                                                                                                  │
│ C:\Users\snomi\comfy-cli\comfy_cli\ui.py:93 in prompt_input                                      │
│                                                                                                  │
│    90 │   """                                                                                    │
│    91 │   if workspace_manager.skip_prompting and not force_prompting:                           │
│    92 │   │   return default                                                                     │
│ ❱  93 │   return questionary.text(question, default=default).ask()                               │
│    94                                                                                            │
│    95                                                                                            │
│    96 def prompt_multi_select(prompt: str, choices: List[str]) -> List[str]:                     │
│                                                                                                  │
│ ╭────────────────────── locals ───────────────────────╮                                          │
│ │         default = None                              │                                          │
│ │ force_prompting = False                             │                                          │
│ │        question = 'Enter filename to save model as' │                                          │
│ ╰─────────────────────────────────────────────────────╯                                          │
│                                                                                                  │
│ C:\Users\snomi\AppData\Local\Programs\Python\Python312\Lib\site-packages\questionary\prompts\tex │
│ t.py:99 in text                                                                                  │
│                                                                                                  │
│    96 │   │   multiline=multiline,                                                               │
│    97 │   │   **kwargs,                                                                          │
│    98 │   )                                                                                      │
│ ❱  99 │   p.default_buffer.reset(Document(default))                                              │
│   100 │                                                                                          │
│   101 │   return Question(p.app)                                                                 │
│   102                                                                                            │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │           default = None                                                                     │ │
│ │ get_prompt_tokens = <function text.<locals>.get_prompt_tokens at 0x00000267CF4BA2A0>         │ │
│ │       instruction = None                                                                     │ │
│ │            kwargs = {}                                                                       │ │
│ │             lexer = <prompt_toolkit.lexers.base.SimpleLexer object at 0x00000267CF4BE960>    │ │
│ │      merged_style = <prompt_toolkit.styles.style._MergedStyle object at 0x00000267CF4BD100>  │ │
│ │           message = 'Enter filename to save model as'                                        │ │
│ │         multiline = False                                                                    │ │
│ │                 p = <prompt_toolkit.shortcuts.prompt.PromptSession object at                 │ │
│ │                     0x00000267CF4BED80>                                                      │ │
│ │             qmark = '?'                                                                      │ │
│ │             style = None                                                                     │ │
│ │          validate = None                                                                     │ │
│ │         validator = None                                                                     │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ C:\Users\snomi\AppData\Local\Programs\Python\Python312\Lib\site-packages\prompt_toolkit\document │
│ .py:116 in __init__                                                                              │
│                                                                                                  │
│    113 │   │   # cursor position is at the end of the document. This is what makes               │
│    114 │   │   # sense in most places.                                                           │
│    115 │   │   if cursor_position is None:                                                       │
│ ❱  116 │   │   │   cursor_position = len(text)                                                   │
│    117 │   │                                                                                     │
│    118 │   │   # Keep these attributes private. A `Document` really has to be                    │
│    119 │   │   # considered to be immutable, because otherwise the caching will break            │
│                                                                                                  │
│ ╭────────────────────────────────── locals ───────────────────────────────────╮                  │
│ │ cursor_position = None                                                      │                  │
│ │       selection = None                                                      │                  │
│ │            self = <repr-error "'Document' object has no attribute '_text'"> │                  │
│ │            text = None                                                      │                  │
│ ╰─────────────────────────────────────────────────────────────────────────────╯                  │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: object of type 'NoneType' has no len()