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: better error message for missing artifacts #973

Merged
merged 5 commits into from
Feb 5, 2025

Conversation

Natoandro
Copy link
Contributor

@Natoandro Natoandro commented Feb 4, 2025

  • Solve MET-821
    • Better error message for missing artifacts
    • Shared logic for artifact registration on postprocess

Migration notes


  • The change comes with new or modified tests
  • Hard-to-understand functions have explanatory comments
  • End-user documentation is updated to reflect the change

Summary by CodeRabbit

  • New Features

    • Consolidated the artifact registration process to support bulk handling of primary and dependency artifacts.
  • Refactor

    • Streamlined registration workflows across multiple runtime integrations, enhancing efficiency and clarity.
  • Tests

    • Added comprehensive tests to ensure robust error reporting when dependencies are missing.
    • Introduced a new test case to validate behavior for non-existent engine scripts.

Copy link

linear bot commented Feb 4, 2025

Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

📝 Walkthrough

Walkthrough

This pull request refactors artifact registration across the system. The ArtifactsExt trait and its FsContext implementation now replace the single artifact method with register_artifacts, which accepts an entry point and a list of dependency paths and returns a vector of registered artifacts. Consequently, all postprocessing routines (for Deno, Python, Substantial, and Wasm processors) have been updated to call this new method, thus streamlining the control flow and error handling. Additionally, test cases have been enhanced to validate error handling when artifacts are missing, and a new runtime helper function has been added.

Changes

File(s) Change Summary
src/typegraph/.../artifacts.rs Replaced register_artifact with a new register_artifacts method in the ArtifactsExt trait. The original single-artifact method was moved to a private helper within FsContext.
src/typegraph/.../postprocess/deno_rt.rs,
src/typegraph/.../postprocess/python_rt.rs,
src/typegraph/.../postprocess/substantial_rt.rs,
src/typegraph/.../postprocess/wasm_rt.rs
Updated the postprocess implementations for various processors to use register_artifacts, consolidating artifact registration and modifying the flow for handling dependencies.
tests/artifacts/artifacts_test.ts,
tests/runtimes/deno/inexisting_dep.py
Enhanced testing by importing additional assertion helpers and adding a new test case for missing artifacts. Introduced a new function to set up a Deno runtime with method exposure and dependency configuration.

Sequence Diagram(s)

sequenceDiagram
    participant P as Processor (Deno/Python/Substantial/Wasm)
    participant FS as FsContext
    participant TG as Typegraph
    P->>FS: register_artifacts(tg, entry, deps)
    FS->>FS: Register main artifact (entry)
    loop For each dependency in deps
       FS->>FS: Call private register_artifact
    end
    FS-->>P: Return list of registered artifacts
    P->>TG: Update artifact/dependency registration
Loading

Possibly related PRs

  • refactor: move to ghjk 0.2.0 #754: The changes in the main PR, specifically the introduction of the register_artifacts method in the ArtifactsExt trait, are directly related to the modifications in the postprocess methods of various processors in the retrieved PR, which now utilize this new method for artifact registration.
  • feat: worker pooling #962: The changes in the main PR, specifically the introduction of the register_artifacts method in the ArtifactsExt trait and its implementation, are directly related to the modifications in the postprocess methods of various processors in the retrieved PR, which now utilize this new method for artifact registration.
  • fix(SDK): Artifact upload fails when same file referred multiple times #715: The changes in the main PR, specifically the introduction of the register_artifacts method in the ArtifactsExt trait, are directly related to the modifications in the retrieved PR, which also involves handling artifacts more efficiently by replacing individual artifact registration with a call to register_artifacts. This indicates a strong connection at the code level.

Suggested reviewers

  • michael-0acf4
  • Yohe-Am
  • zifeo
  • luckasRanarison

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 136b976 and 93a3bfa.

⛔ Files ignored due to path filters (2)
  • deno.lock is excluded by !**/*.lock
  • tests/e2e/nextjs/apollo/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • tests/e2e/nextjs/apollo/package.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test-full
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: pre-commit
🔇 Additional comments (2)
tests/e2e/nextjs/apollo/package.json (2)

12-17: Dependency Versions Updated Correctly.
The versions for "@apollo/client", "apollo-upload-client", "graphql", "next", "react", and "react-dom" have been updated to more specific releases. This pinning helps ensure compatibility with the updated artifact registration logic elsewhere in the system. Please verify that these versions satisfy any cross-dependencies within your project.


20-29: DevDependency Versions Updated Successfully.
The updated devDependencies now use explicit version numbers for packages such as "@types/apollo-upload-client", "@types/node", "@types/react", "@types/react-dom", "autoprefixer", "eslint", "eslint-config-next", "postcss", "tailwindcss", and "typescript". This clarifies the environment setup and should prevent accidental breakage from future minor releases. Please double-check that these changes do not conflict with the tooling configurations (linting, type checking, etc.).


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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
Contributor

@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: 0

🧹 Nitpick comments (3)
tests/runtimes/deno/inexisting_dep.py (1)

1-25: Add a brief docstring for clarity
Even though it’s a test helper, a concise docstring explaining that this TypeGraph function is expected to fail due to a missing dependency ensures better maintainability and clarity for future contributors.

src/typegraph/core/src/utils/postprocess/substantial_rt.rs (1)

24-34: LGTM! Clean implementation with proper mutation handling.

The implementation correctly handles the nested workflow structure while maintaining the same artifact registration pattern.

Consider extracting the workflow processing logic into a separate method for better readability:

 impl SubstantialProcessor {
+    fn process_workflow(
+        &self,
+        tg: &mut Typegraph,
+        fs_ctx: &FsContext,
+        wf_description: &mut WorkflowDescription,
+    ) -> Result<(), crate::errors::TgError> {
+        let entrypoint = wf_description.file.clone();
+        let deps = std::mem::take(&mut wf_description.deps);
+        wf_description.deps = fs_ctx.register_artifacts(tg, entrypoint, deps)?;
+        Ok(())
+    }
tests/artifacts/artifacts_test.ts (1)

207-225: LGTM! Comprehensive test for missing artifact scenario.

The test properly verifies both the error throwing and the error message content, aligning with the PR objective.

Consider adding a test case for multiple missing artifacts to ensure the error message handles this scenario well:

 Meta.test({
   only: mode === "default",
   name: `Missing artifact (mode: ${mode})`,
   ...options,
 }, async (t) => {
   await t.should("fail on missing artifact", async () => {
     await assertRejects(
       async () => {
         await t.engine("runtimes/deno/inexisting_dep.py");
       },
     );
     try {
       await t.engine("runtimes/deno/inexisting_dep.py");
       assert(false, "should have thrown");
     } catch (e) {
       assertStringIncludes(e.message, "no artifacts found for dependency");
     }
   });
+  await t.should("fail on multiple missing artifacts", async () => {
+    try {
+      await t.engine("runtimes/deno/multiple_missing_deps.py");
+      assert(false, "should have thrown");
+    } catch (e) {
+      assertStringIncludes(e.message, "no artifacts found for dependency");
+      // Verify all missing dependencies are mentioned
+      assertStringIncludes(e.message, "dep1.py");
+      assertStringIncludes(e.message, "dep2.py");
+    }
+  });
 });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 82600b5 and 7566b90.

📒 Files selected for processing (7)
  • src/typegraph/core/src/utils/artifacts.rs (1 hunks)
  • src/typegraph/core/src/utils/postprocess/deno_rt.rs (1 hunks)
  • src/typegraph/core/src/utils/postprocess/python_rt.rs (1 hunks)
  • src/typegraph/core/src/utils/postprocess/substantial_rt.rs (1 hunks)
  • src/typegraph/core/src/utils/postprocess/wasm_rt.rs (1 hunks)
  • tests/artifacts/artifacts_test.ts (2 hunks)
  • tests/runtimes/deno/inexisting_dep.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: test-full
  • GitHub Check: pre-commit
🔇 Additional comments (7)
src/typegraph/core/src/utils/artifacts.rs (3)

12-18: Refactor enables multi-artifact registration effectively
Defining a single method that accepts both the entry artifact and its dependencies is a good architectural step toward streamlined artifact handling.


21-45: Consider returning the entry artifact in the result
Currently, the function appends only dependency artifacts to the returned list. If you would like the caller to have a complete record of all registered artifacts (including the entry), consider pushing the entry artifact as well to avoid confusion.


49-60: Private method effectively updates typegraph metadata
This helper method appears clean and logically consistent. The usage of a hash and size for each artifact is aligned with standard artifact tracking.

src/typegraph/core/src/utils/postprocess/wasm_rt.rs (1)

37-37: Transition from single to multi-artifact registration looks correct
Adopting register_artifacts is consistent with the new interface. Passing an empty dependency list here aligns with the logic that no additional WASM artifacts are needed.

src/typegraph/core/src/utils/postprocess/python_rt.rs (1)

33-35: LGTM! Clean implementation of consolidated artifact registration.

The changes align with the new pattern of using register_artifacts and maintain proper error propagation.

Let's verify that the error message for missing artifacts is properly propagated:

✅ Verification successful

Let's gather a bit more detail on the implementation of register_artifacts to verify its error propagation. Please run the following shell scripts:

After reviewing the output, we can confirm whether the error message for missing artifacts is correctly propagated (for example, if the function returns a Result and leverages the ? operator or explicit error conversion).


Verification of Error Propagation in register_artifacts

  • The implementation in src/typegraph/core/src/utils/artifacts.rs correctly returns an error using Err when no artifacts are found.
  • The error message ("no artifacts found for dependency ...") is appropriately propagated via the ? operator in the caller's context.

Everything appears to be working as expected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for error handling in the register_artifacts implementation
ast-grep --pattern 'fn register_artifacts($_, $_, $_) {
  $$$
  Err($_)
  $$$
}'

Length of output: 82


Script:

#!/bin/bash
# Locate the definition of register_artifacts and show surrounding context for inspection of error handling
rg -n "fn register_artifacts" --context 15 .

Length of output: 2845

src/typegraph/core/src/utils/postprocess/deno_rt.rs (1)

31-33: LGTM! Consistent implementation with other processors.

The changes maintain the same pattern of consolidated artifact registration while properly handling Deno-specific module data.

tests/artifacts/artifacts_test.ts (1)

7-12: LGTM! Clean import organization.

The imports are properly organized and include all necessary assertion functions.

Copy link
Contributor

@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: 0

🧹 Nitpick comments (2)
tests/artifacts/artifacts_test.ts (2)

208-222: Simplify error assertion logic.

The test has redundant error checking logic. Consider combining the assertions into a single, more descriptive test.

Here's a suggested improvement:

 Meta.test(`Missing artifact`, async (t) => {
   await t.should("fail on missing artifact", async () => {
     await assertRejects(
       async () => {
         await t.engine("runtimes/deno/inexisting_dep.py");
       },
-    );
-    try {
-      await t.engine("runtimes/deno/inexisting_dep.py");
-      assert(false, "should have thrown");
-    } catch (e) {
-      assertStringIncludes(e.message, "no artifacts found for dependency");
-    }
+      Error,
+      "no artifacts found for dependency",
+      "should throw an error when artifact dependency is missing"
+    );
   });
 });

208-222: Consider adding more test cases for comprehensive error handling.

While the current test verifies basic error handling, consider adding test cases for:

  1. Multiple missing artifacts
  2. Partially missing artifacts
  3. Different types of artifact dependencies

This would ensure robust error handling across various scenarios.

Would you like me to help generate additional test cases to improve coverage?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7566b90 and 136b976.

📒 Files selected for processing (1)
  • tests/artifacts/artifacts_test.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
  • GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
  • GitHub Check: test-full
  • GitHub Check: pre-commit
🔇 Additional comments (1)
tests/artifacts/artifacts_test.ts (1)

7-12: LGTM! Clean import organization.

The new imports are well-structured and necessary for the enhanced error testing capabilities.

Yohe-Am
Yohe-Am previously approved these changes Feb 4, 2025
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.85%. Comparing base (82600b5) to head (93a3bfa).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #973   +/-   ##
=======================================
  Coverage   77.85%   77.85%           
=======================================
  Files         160      160           
  Lines       19641    19641           
  Branches     1969     1969           
=======================================
  Hits        15291    15291           
  Misses       4329     4329           
  Partials       21       21           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Natoandro Natoandro requested a review from Yohe-Am February 5, 2025 05:57
@Natoandro Natoandro merged commit 47d1005 into main Feb 5, 2025
13 checks passed
@Natoandro Natoandro deleted the met-821-error-missing-deps branch February 5, 2025 06:33
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