Skip to content

fix: _ensure_hf_token swallows click.Abort, causing misleading warning #936

Description

@alfredoclarifai

Bug

When running clarifai model local-runner (or any command that calls _ensure_hf_token) from a directory without a config.yaml, the CLI produces a confusing sequence of outputs:

  1. A correct [ERROR] log: config.yaml not found in model path.
  2. A misleading [WARNING]: Unexpected error ensuring HF_TOKEN: (with an empty message)
  3. A full AssertionError traceback from ModelBuilder._validate_folder

The expected behavior is that the CLI should abort cleanly at step 1 and never reach steps 2 or 3.

Root Cause

In clarifai/cli/model.py, the _ensure_hf_token function raises click.Abort() when config.yaml is missing (line 865), but the outer except Exception as e block (line 887) catches it:

try:
    ...
    if not os.path.isfile(config_path):
        logger.error("`config.yaml` not found in model path.")
        raise click.Abort()   # intended to stop execution
    ...
except Exception as e:
    # catches click.Abort too — swallows the abort and downgrades it to a warning
    logger.warning(f"Unexpected error ensuring HF_TOKEN: {e}")

Since click.Abort() has no message string, {e} renders as empty, producing the cryptic Unexpected error ensuring HF_TOKEN: warning. Execution then continues past _ensure_hf_token, and the next thing that fails is the ModelBuilder assertion — producing a noisy traceback.

Fix

Add a specific except click.Abort: raise before the general except Exception handler so the abort propagates as intended:

except click.Abort:
    raise
except Exception as e:
    logger.warning(f"Unexpected error ensuring HF_TOKEN: {e}")

Affected Commands

_ensure_hf_token is called by multiple CLI commands:

  • clarifai model upload
  • clarifai model download-checkpoints
  • clarifai model local-runner
  • clarifai model local-grpc
  • clarifai model signatures

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions