Skip to content

AttributeError when credentials file exists but is empty #226

@lc-cbot

Description

@lc-cbot

Bug Description

When the ~/.limacharlie credentials file exists but is empty (0 bytes), the SDK crashes with an unhandled AttributeError instead of providing a helpful error message.

Steps to Reproduce

  1. Create an empty credentials file: touch ~/.limacharlie
  2. Run any limacharlie CLI command (e.g., limacharlie org list)

Expected Behavior

The SDK should detect the empty/invalid credentials file and display a helpful error message, e.g.:

"Credentials file ~/.limacharlie is empty or corrupted. Run 'limacharlie auth login' to reconfigure."

Actual Behavior

Traceback (most recent call last):
  File "/home/user/.local/bin/limacharlie", line 5, in <module>
    from limacharlie.__main__ import main
  File "/home/user/.local/lib/python3.11/site-packages/limacharlie/__init__.py", line 54, in <module>
    GLOBAL_OID, GLOBAL_UID, GLOBAL_API_KEY = _getEnvironmentCreds( _lcEnv )
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/limacharlie/__init__.py", line 27, in _getEnvironmentCreds
    oid = credsFile.get( 'oid', None )
          ^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'

Root Cause

In __init__.py, _getEnvironmentCreds reads the credentials file and parses it. When the file is empty, the parser returns None, but the code assumes it will always be a dict and calls .get() on it without a null check.

Suggested Fix

Add a guard after parsing the credentials file:

if credsFile is None:
    credsFile = {}

Or raise a descriptive error prompting the user to re-authenticate.

Environment

  • limacharlie version: 5.0.2
  • Python version: 3.11
  • OS: Linux

Metadata

Metadata

Assignees

No one assigned

    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