SkuldNorniern / fluere

Fluere is a powerful and versatile tool designed for network monitoring and analysis. It is capable of capturing network packets in pcap format and converting them into NetFlow data, providing a comprehensive view of network traffic. It also Provides Terminal User Interface.
Apache License 2.0
29 stars 3 forks source link

Fix panic on `fluere-config/src/init.rs:14:43` #73

Closed sweep-ai[bot] closed 8 months ago

sweep-ai[bot] commented 8 months ago

PR Feedback: πŸ‘

Description

This PR fixes a panic that occurs in the fluere-config/src/init.rs file when trying to create a directory at a path that is not supported by the operating system. The panic is caused by an unwrap() call on a Result object that contains an Err value. This PR replaces the unwrap() call with error handling code to prevent the panic and provide a more graceful error handling mechanism.

Summary of Changes

Fixes #72.


πŸŽ‰ Latest improvements to Sweep:


πŸ’‘ To get Sweep to edit this pull request, you can:

Summary by CodeRabbit

sweep-ai[bot] commented 8 months ago

Sandbox Executions

trunk init 1/3 βœ“
β‘Ώ Downloading Trunk 1.17.1...
β‘Ώ Downloading Trunk 1.17.1...
β’Ώ Downloading Trunk 1.17.1...
β£» Downloading Trunk 1.17.1...
β£½ Downloading Trunk 1.17.1...
β£Ύ Downloading Trunk 1.17.1...
β£· Downloading Trunk 1.17.1...
βœ” Downloading Trunk 1.17.1... done
β‘Ώ Verifying Trunk sha256...
βœ” Verifying Trunk sha256... done
β‘Ώ Unpacking Trunk...
βœ” Unpacking Trunk... done

βœ” 14 linters were enabled (.trunk/trunk.yaml)
  actionlint 1.6.26 (5 github-workflow files)
  checkov 3.0.16 (12 yaml files)
  clippy 1.65.0 (5 rust files)
  git-diff-check (83 files)
  markdownlint 0.37.0 (8 markdown files) (created .markdownlint.yaml)
  oxipng 9.0.0 (3 png files)
  prettier 3.0.3 (8 markdown, 12 yaml files)
  rustfmt 1.65.0 (50 rust files) (created .rustfmt.toml)
  shellcheck 0.9.0 (2 shell files) (created .shellcheckrc)
  shfmt 3.6.0 (2 shell files)
  taplo 0.8.1 (5 toml files)
  trivy 0.46.1 (12 yaml files)
  trufflehog 3.62.1 (83 files)
  yamllint 1.32.0 (12 yaml files) (created .yamllint.yaml)
Next Steps
 1. Read documentation
    Our documentation can be found at https://docs.trunk.io
 2. Get help and give feedback
    Join the Trunk community at https://slack.trunk.io
trunk fmt fluere-config/src/init.rs || exit 0 2/3 βœ“
Checked 1 file
βœ” No issues
trunk check --fix --print-failures fluere-config/src/init.rs 3/3 ❌ (`1`)
  FAILURES  
 clippy  fluere-config  .trunk/out/ym3yR.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 1 file
βœ– No issues, 1 failure
# .trunk/out/ym3yR.yaml
trunk_cli_version: 1.17.1
title: "Error while executing: fluere-config"
report:
  - Unable to find fluere-config for Cargo.lock in any parent directory of /repo/fluere-config
  - linter:
      command: |
        /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps
      stdin_path: (none)
      run_from: /repo/fluere-config
      timeout: 10m
      rerun: (cd /repo/fluere-config; env -i PATH=/root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin:/root/.nvm/versions/node/v18.17.0/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin CARGO_TARGET_DIR=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_target_dir HOME=/root CARGO_HOME=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_home /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps)
      affects_cache:
        - Cargo.toml
      direct_configs:
        []
      exit_status: exited
      exit_code: 101
      stdout: (none)
      stderr: |
            Updating crates.io index
            Updating git repository `https://github.com/SkuldNorniern/pcap`
        error: the lock file /repo/Cargo.lock needs to be updated but --locked was passed to prevent this
        If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
    parser: |
      (none)

trunk fmt Cargo.toml || exit 0 1/2 βœ“
 βœ” Formatted Cargo.toml
Re-checking autofixed files...

Checked 1 file
βœ” No issues
trunk check --fix --print-failures Cargo.toml 2/2 βœ“
Checked 1 file
βœ” No issues

trunk fmt fluere-config/src/init.rs || exit 0 1/2 βœ“
Checked 1 file
βœ” No issues
trunk check --fix --print-failures fluere-config/src/init.rs 2/2 ❌ (`1`)
  FAILURES  
 clippy  fluere-config  .trunk/out/GSdZe.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 1 file
βœ– No issues, 1 failure
# .trunk/out/GSdZe.yaml
trunk_cli_version: 1.17.1
title: "Error while executing: fluere-config"
report:
  - Unable to find fluere-config for Cargo.lock in any parent directory of /repo/fluere-config
  - linter:
      command: |
        /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps
      stdin_path: (none)
      run_from: /repo/fluere-config
      timeout: 10m
      rerun: (cd /repo/fluere-config; env -i PATH=/root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin:/root/.nvm/versions/node/v18.17.0/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=/root CARGO_TARGET_DIR=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_target_dir CARGO_HOME=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_home /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps)
      affects_cache:
        - Cargo.toml
      direct_configs:
        []
      exit_status: exited
      exit_code: 101
      stdout: (none)
      stderr: |
            Updating crates.io index
            Updating git repository `https://github.com/SkuldNorniern/pcap`
        error: failed to select a version for the requirement `fluere-config = "^0.1.1"`
        candidate versions found which didn't match: 0.1.0
        location searched: /repo/fluere-config
        required by package `fluere v0.6.1 (/repo)`
    parser: |
      (none)

trunk fmt Cargo.toml || exit 0 1/2 βœ“
Checked 1 file
βœ” No issues
trunk check --fix --print-failures Cargo.toml 2/2 βœ“
Checked 1 file
βœ” No issues

trunk fmt fluere-config/src/init.rs || exit 0 1/2 βœ“
Checked 1 file
βœ” No issues
trunk check --fix --print-failures fluere-config/src/init.rs 2/2 ❌ (`1`)
  FAILURES  
 clippy  fluere-config  .trunk/out/2wrGD.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 1 file
βœ– No issues, 1 failure
# .trunk/out/2wrGD.yaml
trunk_cli_version: 1.17.1
title: "Error while executing: fluere-config"
report:
  - Unable to find fluere-config for Cargo.lock in any parent directory of /repo/fluere-config
  - linter:
      command: |
        /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps
      stdin_path: (none)
      run_from: /repo/fluere-config
      timeout: 10m
      rerun: (cd /repo/fluere-config; env -i PATH=/root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin:/root/.nvm/versions/node/v18.17.0/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin CARGO_TARGET_DIR=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_target_dir HOME=/root CARGO_HOME=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_home /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps)
      affects_cache:
        - Cargo.toml
      direct_configs:
        []
      exit_status: exited
      exit_code: 101
      stdout: (none)
      stderr: |
            Updating crates.io index
            Updating git repository `https://github.com/SkuldNorniern/pcap`
        error: the lock file /repo/Cargo.lock needs to be updated but --locked was passed to prevent this
        If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
    parser: |
      (none)

trunk fmt Cargo.lock || exit 0 1/2 βœ“
Found no applicable linters for the requested path
trunk check --fix --print-failures Cargo.lock 2/2 βœ“
  NOTICES  
 Cargo.lock  ignored by .gitignore and trunk.yaml [git-diff-check]
 Hint: use --force to check ignored files
Found no applicable linters for the requested path

trunk fmt fluere-config/src/init.rs || exit 0 1/2 βœ“
Checked 1 file
βœ” No issues
trunk check --fix --print-failures fluere-config/src/init.rs 2/2 ❌ (`1`)
  FAILURES  
 clippy  fluere-config  .trunk/out/fxoVA.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 1 file
βœ– No issues, 1 failure
# .trunk/out/fxoVA.yaml
trunk_cli_version: 1.17.1
title: "Error while executing: fluere-config"
report:
  - clippy exited with exit_code=101
  - linter:
      command: |
        /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps
      stdin_path: (none)
      run_from: /repo/fluere-config
      timeout: 10m
      rerun: (cd /repo/fluere-config; env -i PATH=/root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin:/root/.nvm/versions/node/v18.17.0/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=/root CARGO_HOME=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_home CARGO_TARGET_DIR=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_target_dir /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps)
      affects_cache:
        - Cargo.toml
        - Cargo.lock
      direct_configs:
        []
      exit_status: exited
      exit_code: 101
      stdout: (none)
      stderr: |
        error: failed to parse lock file at: /repo/Cargo.lock
        Caused by:
          could not parse input as TOML
        Caused by:
          TOML parse error at line 1, column 4
            |
          1 | As the `Cargo.lock` file is generated and updated automatically by the Cargo package manager, there is no need to manually create or modify this file. Therefore, there is no new file content to provide in this section.
            |    ^
          Unexpected `t`
          Expected `.` or `=`
    parser: |
      (none)

trunk fmt Cargo.lock || exit 0 1/2 βœ“
Found no applicable linters for the requested path
trunk check --fix --print-failures Cargo.lock 2/2 βœ“
  NOTICES  
 Cargo.lock  ignored by .gitignore and trunk.yaml [git-diff-check]
 Hint: use --force to check ignored files
Found no applicable linters for the requested path

trunk fmt fluere-config/src/init.rs || exit 0 1/2 βœ“
Checked 1 file
βœ” No issues
trunk check --fix --print-failures fluere-config/src/init.rs 2/2 ❌ (`1`)
  FAILURES  
 clippy  fluere-config  .trunk/out/OwFev.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 1 file
βœ– No issues, 1 failure
# .trunk/out/OwFev.yaml
trunk_cli_version: 1.17.1
title: "Error while executing: fluere-config"
report:
  - clippy exited with exit_code=101
  - linter:
      command: |
        /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps
      stdin_path: (none)
      run_from: /repo/fluere-config
      timeout: 10m
      rerun: (cd /repo/fluere-config; env -i PATH=/root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin:/root/.nvm/versions/node/v18.17.0/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=/root CARGO_HOME=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_home CARGO_TARGET_DIR=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_target_dir /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps)
      affects_cache:
        - Cargo.toml
        - Cargo.lock
      direct_configs:
        []
      exit_status: exited
      exit_code: 101
      stdout: (none)
      stderr: |
            Updating crates.io index
            Updating git repository `https://github.com/SkuldNorniern/pcap`
        error: the lock file /repo/Cargo.lock needs to be updated but --locked was passed to prevent this
        If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
    parser: |
      (none)

trunk fmt fluere-config/src/init.rs || exit 0 1/2 βœ“
Checked 1 file
βœ” No issues
trunk check --fix --print-failures fluere-config/src/init.rs 2/2 ❌ (`1`)
  FAILURES  
 clippy  fluere-config  .trunk/out/OwFev.yaml
  NOTICES  
 A tool failed to run. You can open the details yaml file for more information.
Checked 1 file
βœ– No issues, 1 failure
# .trunk/out/OwFev.yaml
trunk_cli_version: 1.17.1
title: "Error while executing: fluere-config"
report:
  - clippy exited with exit_code=101
  - linter:
      command: |
        /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps
      stdin_path: (none)
      run_from: /repo/fluere-config
      timeout: 10m
      rerun: (cd /repo/fluere-config; env -i PATH=/root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin:/root/.nvm/versions/node/v18.17.0/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=/root CARGO_HOME=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_home CARGO_TARGET_DIR=/root/.cache/trunk/repos/f97b771eaa16b34ad180abf83b26f9a7/results/clippy-current/cargo_target_dir /root/.cache/trunk/tools/rust/1.65.0-f09848e9e4f55504aac7f8b8e2f48445/bin/cargo clippy --message-format json --locked -- --cap-lints=warn --no-deps)
      affects_cache:
        - Cargo.toml
        - Cargo.lock
      direct_configs:
        []
      exit_status: exited
      exit_code: 101
      stdout: (none)
      stderr: |
            Updating crates.io index
            Updating git repository `https://github.com/SkuldNorniern/pcap`
        error: the lock file /repo/Cargo.lock needs to be updated but --locked was passed to prevent this
        If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
    parser: |
      (none)

sweep-ai[bot] commented 8 months ago

Apply Sweep Rules to your PR?

coderabbitai[bot] commented 8 months ago

[!IMPORTANT]

Auto Review Skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The recent changes to the Fluere project focus on enhancing error handling and improving code readability. The Config implementation now handles directory creation failures gracefully, and the PluginManager has been refactored for clarity. Additionally, error messages have been added to the cleanup function for better debugging.

Changes

File Path Summary
fluere-config/src/.../init.rs Added error handling for directory creation in the Config implementation. If directory creation fails, a default Config object is returned.
fluere-plugin/src/.../lib.rs Improved readability of the PluginManager implementation. The lua_plugin_path variable is now split into multiple lines, and for loops have been reformatted. Added error messages to the cleanup function.

Poem

πŸ‚ As autumn leaves fall, we code with glee, 🍁

For Fluere's changes are as sweet as tea. β˜•

With error handling now in place, πŸ› οΈ

And code that's clear as crystal vase. πŸ’Ž

In the spirit of the season's grace, πŸ‚

We celebrate our codebase's new face. πŸŽ‰

So here's to Fluere, steady as a tree, 🌳

Evolving, growing, as free as can be. πŸ•ŠοΈ


Tips ### Chat with CodeRabbit Bot (`@coderabbitai`) - If you reply to a *review comment* from CodeRabbit, the bot will automatically respond. - To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment - Note: Review comments are made on code diffs or files, not on the PR overview. - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai help` to get help. - `@coderabbitai resolve` to resolve all the CodeRabbit review comments. Note: For conversation with the bot, please use the review comments on code diffs or files. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - The JSON schema for the configuration file is available [here](https://coderabbit.ai/integrations/coderabbit-overrides.json). - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json`
SkuldNorniern commented 8 months ago

@coderabbitai review

sweep-ai[bot] commented 8 months ago

❌ Could not find files to change

Please join our Discord to report this issue.

SkuldNorniern commented 8 months ago

remove Cargo.lock file

sweep-ai[bot] commented 8 months ago

πŸš€ Wrote Changes

I wasn't able to make changes. This could be due to an unclear request or a bug in my code. As a reminder, comments on a file only modify that file. Comments on a PR (at the bottom of the "conversation" tab) can modify the entire PR. Please try again or contact us on Discord