Skip to content

Conversation

@LunaStev
Copy link
Member

@LunaStev LunaStev commented Jul 14, 2025

Added directory support from local import, including error message improvement.

  • import("math"); -> project_root/math.wave
  • import("math/math") -> project_root/math/math.wave

Error Message Example:

error: Could not find import target 'math.wave'
  --> math.wave:0:0
   |
   | (source unavailable)

Summary by CodeRabbit

  • Refactor

    • Improved error handling for local module imports, providing more detailed diagnostic messages for import failures.
  • Style

    • Simplified the version tag format in the application metadata.

@LunaStev LunaStev self-assigned this Jul 14, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 14, 2025

Walkthrough

The local_import function was refactored to return a Result with detailed error handling instead of an Option, providing explicit diagnostics for import failures. Corresponding changes in import handling logic were made in src/runner.rs. The package version in Cargo.toml was simplified from a nightly-dated pre-release to a generic pre-beta tag.

Changes

File(s) Change Summary
Cargo.toml Changed version string from 0.1.3-pre-beta-nightly-2025-07-11 to 0.1.3-pre-beta.
front/parser/src/parser/import.rs Refactored local_import to return Result<Vec<ASTNode>, WaveError> with detailed error handling.
src/runner.rs Updated import logic to handle Result from local_import, improving error reporting.

Sequence Diagram(s)

sequenceDiagram
    participant Runner
    participant Importer
    participant FileSystem
    participant Lexer
    participant Parser

    Runner->>Importer: local_import(path, already_imported, base_dir)
    Importer->>FileSystem: Check if file exists and is valid
    alt File not found or invalid
        Importer-->>Runner: Err(WaveError)
    else File found
        Importer->>FileSystem: Read file content
        Importer->>Lexer: Tokenize content
        Importer->>Parser: Parse tokens
        alt Parse error
            Importer-->>Runner: Err(WaveError with diagnostics)
        else Success
            Importer-->>Runner: Ok(Vec<ASTNode>)
        end
    end
    Runner->>Runner: Handle Ok or display error from Err
Loading

Possibly related PRs

  • LunaStev/Wave#207: Also updates the version string in Cargo.toml, showing a similar context of version management.
  • LunaStev/Wave#202: Modifies the Cargo.toml version string, related through changes in versioning approach.
  • LunaStev/Wave#153: Originally introduced the local_import function; this PR directly refactors and improves its error handling.

Poem

In the warren of code, a new path we tread,
Imports now speak when they stumble or dread.
No more silent burrows where errors would hide,
With clear Result voices, our rabbits confide.
The version hops lighter, pre-beta in view—
🐇✨ Onward we code, with clarity anew!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Clippy (1.86.0)
Updating crates.io index

warning: failed to write cache, path: /usr/local/registry/index/index.crates.io-1949cf8c6b5b557f/.cache/re/ge/regex, error: Permission denied (os error 13)
Locking 22 packages to latest compatible versions
Adding inkwell v0.5.0 (available: v0.6.0)
Adding llvm-sys v140.1.3 (available: v201.0.1)
Downloading crates ...
Downloaded inkwell_internals v0.10.0
error: failed to create directory /usr/local/registry/cache/index.crates.io-1949cf8c6b5b557f

Caused by:
Permission denied (os error 13)

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
front/parser/src/parser/import.rs (1)

91-107: Remove or document unused function find_wave_file_recursive.

This helper is only ever called by itself (for recursion) and isn’t invoked anywhere else in the codebase. To keep the code clean:

  • Location: front/parser/src/parser/import.rs (lines 91–107)
  • Actions:
    • Remove the entire function if it’s no longer needed.
    • Otherwise, add a comment or #[allow(dead_code)] annotation explaining its intended future use.
🧹 Nitpick comments (1)
front/parser/src/parser/import.rs (1)

77-86: Consider using actual parse error location.

The error uses hardcoded line/column numbers (1, 1) which may not reflect the actual error location in the imported file.

If the parser provides error location information, consider extracting and using it for more accurate error reporting. This would improve the debugging experience when imports fail to parse.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd10cdc and 82f5595.

📒 Files selected for processing (3)
  • Cargo.toml (1 hunks)
  • front/parser/src/parser/import.rs (1 hunks)
  • src/runner.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/runner.rs (1)
front/parser/src/parser/import.rs (1)
  • local_import (8-89)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (3)
Cargo.toml (1)

3-3: LGTM! Version simplification is appropriate.

The version change from a dated nightly build to a cleaner pre-beta tag aligns well with the import system improvements.

front/parser/src/parser/import.rs (1)

8-21: Good error handling for empty paths.

The Result-based approach with explicit error messages improves the developer experience as intended by the PR.

src/runner.rs (1)

31-39: Proper error handling implementation.

The updated code correctly handles the Result type from local_import, displaying detailed error information before exiting. This aligns perfectly with the PR's goal of improving error messages.

Comment on lines +49 to +57
let abs_path_str = abs_path.to_str().ok_or_else(|| {
WaveError::new(
WaveErrorKind::UnexpectedChar('?'),
"Invalid path encoding",
target_file_name.clone(),
0,
0,
)
})?.to_string();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use appropriate error kind for path encoding issues.

WaveErrorKind::UnexpectedChar('?') is semantically incorrect for path encoding errors. This error kind is typically used for lexical analysis, not filesystem operations.

Consider using a more appropriate error kind:

-        WaveError::new(
-            WaveErrorKind::UnexpectedChar('?'),
-            "Invalid path encoding",
+        WaveError::new(
+            WaveErrorKind::SyntaxError("Invalid path encoding".to_string()),
+            "Path contains invalid UTF-8 characters",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let abs_path_str = abs_path.to_str().ok_or_else(|| {
WaveError::new(
WaveErrorKind::UnexpectedChar('?'),
"Invalid path encoding",
target_file_name.clone(),
0,
0,
)
})?.to_string();
let abs_path_str = abs_path.to_str().ok_or_else(|| {
WaveError::new(
WaveErrorKind::SyntaxError("Invalid path encoding".to_string()),
"Path contains invalid UTF-8 characters",
target_file_name.clone(),
0,
0,
)
})?.to_string();
🤖 Prompt for AI Agents
In front/parser/src/parser/import.rs around lines 49 to 57, the error kind used
for invalid path encoding is WaveErrorKind::UnexpectedChar('?'), which is
inappropriate for filesystem-related errors. Replace this with a more suitable
error kind that reflects path or encoding errors, ensuring the error accurately
represents the nature of the failure.

@LunaStev LunaStev merged commit 74b77fe into master Jul 14, 2025
2 checks passed
@LunaStev LunaStev deleted the import branch July 19, 2025 12:26
@LunaStev LunaStev added this to Wave Aug 28, 2025
@LunaStev LunaStev moved this to Done in Wave Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants