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:
- A correct
[ERROR] log: config.yaml not found in model path.
- A misleading
[WARNING]: Unexpected error ensuring HF_TOKEN: (with an empty message)
- 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
Bug
When running
clarifai model local-runner(or any command that calls_ensure_hf_token) from a directory without aconfig.yaml, the CLI produces a confusing sequence of outputs:[ERROR]log:config.yaml not found in model path.[WARNING]:Unexpected error ensuring HF_TOKEN:(with an empty message)AssertionErrortraceback fromModelBuilder._validate_folderThe 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_tokenfunction raisesclick.Abort()whenconfig.yamlis missing (line 865), but the outerexcept Exception as eblock (line 887) catches it:Since
click.Abort()has no message string,{e}renders as empty, producing the crypticUnexpected error ensuring HF_TOKEN:warning. Execution then continues past_ensure_hf_token, and the next thing that fails is theModelBuilderassertion — producing a noisy traceback.Fix
Add a specific
except click.Abort: raisebefore the generalexcept Exceptionhandler so the abort propagates as intended:Affected Commands
_ensure_hf_tokenis called by multiple CLI commands:clarifai model uploadclarifai model download-checkpointsclarifai model local-runnerclarifai model local-grpcclarifai model signatures