Skip to content

CLI crashes with 'Operation not permitted' when log file is not writable #3537

@peterschmidt85

Description

@peterschmidt85

Description

When running the dstack CLI in a sandboxed environment (e.g., from an AI coding agent), the CLI crashes if it cannot write to the log file at ~/.dstack/logs/cli/latest.log.

Steps to Reproduce

  1. Run the dstack CLI in an environment where writing to ~/.dstack/logs/cli/ is restricted (e.g., a sandboxed process)
  2. Any CLI command fails with a PermissionError

Error

Traceback (most recent call last):
  File "/Users/cheptsov/.local/bin/dstack", line 10, in <module>
    sys.exit(main())
  ...
  File ".../dstack/_internal/cli/utils/common.py", line 87, in configure_logging
    file_handler = logging.FileHandler(log_file)
  ...
PermissionError: [Errno 1] Operation not permitted: '/Users/cheptsov/.dstack/logs/cli/latest.log'

Expected Behavior

The CLI should print a warning about the inability to write logs but continue executing normally, falling back to stdout-only logging.

Proposed Fix

Wrap the file handler creation in configure_logging() with a try-except block to catch PermissionError specifically, print a warning, and continue without file logging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions