Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
Nov 3, 2023

Conversation

sweep-ai[bot]
Copy link
Contributor

@sweep-ai sweep-ai bot commented Nov 3, 2023

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

  • Modified fluere-config/src/init.rs to handle the error when creating the directory at line 14.
  • Replaced the unwrap() call with a match expression to handle the Result object returned by the fs::create_dir_all(path_base) function.
  • In the Ok(_) branch of the match expression, no action is taken as the directory creation was successful.
  • In the Err(e) branch, an error message is printed to the console using eprintln!() and the function returns a default Config object to prevent the application from crashing.
  • Added error handling code to improve the stability and reliability of the application.

Fixes #72.


🎉 Latest improvements to Sweep:


💡 To get Sweep to edit this pull request, you can:

  • Comment below, and Sweep can edit the entire PR
  • Comment on a file, Sweep will only modify the commented file
  • Edit the original issue to get Sweep to recreate the PR from scratch

Summary by CodeRabbit

  • New Features
    • Improved error handling for directory creation in the configuration process.
  • Bug Fixes
    • Enhanced error messaging for missing cleanup functions in plugins.
  • Style
    • Improved code readability in the PluginManager implementation.

Copy link
Contributor Author

sweep-ai bot commented Nov 3, 2023

Sandbox Executions

  • Check fluere-config/src/init.rs
Sandbox logs for
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)
  • Check Cargo.toml
Sandbox logs for https://github.com/SkuldNorniern/fluere/commit/4112d3e8d74086ae6b7e5d1216e4e95aefe2f49d
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
  • Check fluere-config/src/init.rs
Sandbox logs for
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)
  • Check Cargo.toml
Sandbox logs for
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
  • Check fluere-config/src/init.rs
Sandbox logs for
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)
  • Check Cargo.lock
Sandbox logs for
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
  • Check fluere-config/src/init.rs
Sandbox logs for
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)
  • Check Cargo.lock
Sandbox logs for
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
  • Check fluere-config/src/init.rs
Sandbox logs for
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)
  • Check Cargo.lock
Run `Cargo.lock` through the sandbox.
  • Check fluere-config/src/init.rs
Sandbox logs for
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)

Copy link
Contributor Author

sweep-ai bot commented Nov 3, 2023

Apply Sweep Rules to your PR?

@sweep-ai sweep-ai bot added the sweep Assigns Sweep to an issue or pull request. label Nov 3, 2023
Copy link

coderabbitai bot commented Nov 3, 2023

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.
  • 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
Copy link
Owner

@coderabbitai review

Copy link
Contributor Author

sweep-ai bot commented Nov 3, 2023

❌ Could not find files to change

Please join our Discord to report this issue.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a059abb and 446aa22.
Files ignored due to filter (2)
  • Cargo.lock
  • Cargo.toml
Files selected for processing (2)
  • fluere-config/src/init.rs (1 hunks)
  • fluere-plugin/src/lib.rs (5 hunks)
Files skipped from review due to trivial changes (1)
  • fluere-plugin/src/lib.rs
Additional comments: 1
fluere-config/src/init.rs (1)
  • 11-23: The error handling for directory creation is well implemented. It's good that you're returning a default Config object in case of an error, which prevents the application from crashing. However, you might want to consider whether returning a default Config is the best approach. If the directory creation fails, it might mean that there are permission issues or the disk is full, and continuing with a default Config might not be the best course of action. You might want to consider propagating the error up and handling it at a higher level, possibly alerting the user to the issue.

Overall:
The code is well written and follows Rust's best practices. The error handling is done correctly and the use of match for handling Result types is appropriate. The code is also quite readable and maintainable.

@SkuldNorniern
Copy link
Owner

remove Cargo.lock file

Copy link
Contributor Author

sweep-ai bot commented Nov 3, 2023

🚀 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

@SkuldNorniern SkuldNorniern merged commit 0efb6ed into main Nov 3, 2023
4 checks passed
@SkuldNorniern SkuldNorniern deleted the sweep/fix-panic-fluere-config branch November 3, 2023 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sweep Assigns Sweep to an issue or pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix(config): panic on fluere-config/src/init.rs:14:43
1 participant