Skip to content

Conversation

@timbrigham-oc
Copy link
Contributor

Skip swap files created by nano while developing rules.

Description

Small fix for app_svc to avoid errors from swp files while locally editing with nano while caldera is running.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Tested locally, after making the change nano editing no longer throws errors (like the following)

                    ERROR    Task exception was never retrieved                                                                                                                                                           base_events.py:1821
                             future: <Task finished name='Task-1981' coro=<AppService.watch_ability_files() done, defined at /usr/local/caldera/app/service/app_svc.py:201> exception=UnicodeDecodeError('utf-8',
                             b'b0nano
                             7.2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xed\xd0\n\x00root\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0
                             0\x00\x00\x00\x00\x00\x00\x00\x00.....00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00data/abilities/execution/999a9999-
                             e761-4c16-891a-3dc4eff02e74.yml\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
    (none needed)
  • I have added tests that prove my fix is effective or that my feature works

Skip swap files created by nano while developing rules
@uruwhy
Copy link
Contributor

uruwhy commented Aug 27, 2025

Thoughts on swapping this out for only accepting .yml/.yaml files and nothing else? This would be more effective than playing whack-a-mole with other file extensions that may pop up due to other text editors

@timbrigham-oc
Copy link
Contributor Author

@uruwhy , that's a great idea honestly.. this was just a quick fix while I was in the middle of another project.. The swp files here are binary and were capable of crashing the caldera instance.

Update logic to exclude all non yml files
@deacon-mp deacon-mp requested a review from Copilot September 29, 2025 23:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a file filter to prevent the application from processing non-YAML files when watching for ability file changes, specifically addressing errors caused by nano editor swap files during development.

  • Adds a check to skip files that don't end with '.yml' extension
  • Includes debug logging for skipped files
  • Prevents UnicodeDecodeError exceptions from binary swap files

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +210 to +211
if not f.endswith('.yml'):
self.log.debug('[%s] Skipping non YML file %s' % (p.name, f))
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The file extension check is case-sensitive and only matches '.yml'. YAML files can also have '.yaml' extension, which would be skipped by this filter. Consider using a case-insensitive check that accepts both '.yml' and '.yaml' extensions.

Suggested change
if not f.endswith('.yml'):
self.log.debug('[%s] Skipping non YML file %s' % (p.name, f))
if not f.lower().endswith(('.yml', '.yaml')):
self.log.debug('[%s] Skipping non YAML file %s' % (p.name, f))

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

@timbrigham-oc

thoughts on this suggestion? I'd keep the tuple part but discard the lower() since the file extensions on linux will be case-sensitive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@uruwhy that's fair, my usually background is on windows hosts, so I make everything case insensitive.
Big thing I was shooting for was avoiding crashing my instance by reading binary temp files.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 6, 2025

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.

3 participants