Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(DevHooks): replace hardcoded Desktop log path with APPDATA, swallow write errors#3376

Open
Copilot wants to merge 3 commits into
developfrom
copilot/fix-log-path-in-hooks-logger
Open

fix(DevHooks): replace hardcoded Desktop log path with APPDATA, swallow write errors#3376
Copilot wants to merge 3 commits into
developfrom
copilot/fix-log-path-in-hooks-logger

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

hooks_logger.py hardcodes %userprofile%\desktop\hooks.log. On machines where Desktop is redirected to OneDrive, that path doesn't exist — every hook fire throws an unhandled IOError, and because progress-changed fires continuously during model load, this produces a cascade of error dialogs that leaks memory until Revit is unusable.

Changes

  • Log path%userprofile%\desktop\hooks.log%APPDATA%\pyRevit\hooks.log (always-valid, writable location)
  • Directory creationos.makedirs ensures the pyRevit subdirectory exists before first write
  • Silent failure_write_record now catches IOError/OSError and passes, so any future path issue never surfaces as a dialog
# before
USER_DESKTOP = op.expandvars('%userprofile%\\desktop')
HOOK_LOGS = op.join(USER_DESKTOP, 'hooks.log')

def _write_record(record_str):
    with open(HOOK_LOGS, 'a') as f:
        f.write(record_str + '\n')

# after
HOOK_LOGS = op.join(os.environ.get('APPDATA', op.expandvars('%userprofile%')),
                    'pyRevit', 'hooks.log')

def _write_record(record_str):
    try:
        log_dir = op.dirname(HOOK_LOGS)
        if not op.exists(log_dir):
            os.makedirs(log_dir)
        with open(HOOK_LOGS, 'a') as f:
            f.write(record_str + '\n')
    except (IOError, OSError):
        pass

@jmcouffin
Copy link
Copy Markdown
Contributor

Fixes #3338

@jmcouffin jmcouffin requested a review from Copilot May 14, 2026 15:44
devloai[bot]

This comment was marked as outdated.

This comment was marked as outdated.

devloai Bot added 2 commits May 14, 2026 15:52
Replace exists()+makedirs() with unconditional makedirs() wrapped in
its own OSError guard. The outer except now only catches real write
failures, preventing a race-created directory from masking permission
errors or other genuine IOErrors.
@jmcouffin jmcouffin marked this pull request as ready for review May 14, 2026 16:17
@tay0thman
Copy link
Copy Markdown
Contributor

@jmcouffin from first glance, it looks to be agood practice, I know @sanzoghenzo is not a fan of os.path and he recommends pathlib, but I think we should keep it the way it was writtem, I will test it on my machine and approve it soon.

Copy link
Copy Markdown
Contributor

@sanzoghenzo sanzoghenzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for not using pathlib, but I still got something to say 😅

f.write(record_str + '\n')
try:
try:
os.makedirs(op.dirname(HOOK_LOGS))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use os.dirname instead of storing and using the directory directly? Something like HOOK_LOGS_DIR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants