Skip to content

Return correct error message from wasmencodedResult in DeploymentSteps#1594

Merged
hardyjosh merged 5 commits intomainfrom
Show-correct-error-message-from-wasmencodedresult-in-deploymentsteps
Apr 5, 2025
Merged

Return correct error message from wasmencodedResult in DeploymentSteps#1594
hardyjosh merged 5 commits intomainfrom
Show-correct-error-message-from-wasmencodedresult-in-deploymentsteps

Conversation

@hardingjam
Copy link
Copy Markdown
Contributor

@hardingjam hardingjam commented Apr 5, 2025

Motivation

Error message wasn't properly surfaced from Rust into the developmentSteps component

image

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • Refactor

    • Streamlined the deployment process error handling for clearer messaging and improved user feedback during deployments.
  • Tests

    • Introduced new test cases for successful retrieval of deployment transaction arguments and error handling scenarios, enhancing the reliability of the deployment functionality.

@hardingjam hardingjam added bug Something isn't working webapp labels Apr 5, 2025
@hardingjam hardingjam requested a review from hardyjosh April 5, 2025 12:44
@hardingjam hardingjam self-assigned this Apr 5, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 5, 2025

Walkthrough

The pull request introduces new test cases for the DeploymentSteps functionality, specifically validating the retrieval of deployment transaction arguments and error handling. The DeploymentSteps.test.ts file now includes tests for both successful and failed retrieval scenarios. Additionally, the error handling logic in the DeploymentSteps.svelte component has been streamlined to return errors directly using DeploymentStepsError.catch, removing redundant UI error alerts. New public entities—a method getDeploymentTransactionArgs and a constant DeploymentStepsErrorCode—were added to facilitate deployment transaction processing and error management.

Changes

File(s) Change Summary
packages/ui-components/src/__tests__/DeploymentSteps.test.ts Added two test cases: one to verify successful retrieval of deployment transaction arguments with modal invocation, and another to ensure a specific error message is displayed when retrieval fails.
packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte Refactored the handleDeployButtonClick function to consolidate error handling by directly returning DeploymentStepsError.catch and removing redundant conditional error alert rendering.
.../deployment/getDeploymentTransactionArgs, $lib/errors/DeploymentStepsError Introduced a new method getDeploymentTransactionArgs and a new constant DeploymentStepsErrorCode to support deployment transactions and standardized error handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DS as DeploymentSteps.svelte
    participant Tx as getDeploymentTransactionArgs
    participant Err as DeploymentStepsError
    participant Modal as Modal/UI
    User->>DS: Click "Deploy"
    DS->>Tx: Call getDeploymentTransactionArgs()
    alt Successful retrieval
        Tx-->>DS: Return transaction args
        DS->>Modal: Open modal with transaction details
    else Error occurs
        Tx-->>DS: Return error
        DS->>Err: Process error using DeploymentStepsError.catch()
        Note over DS: UI error alert rendering removed
    end
Loading

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 88672f8 and a37f16c.

📒 Files selected for processing (1)
  • packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte (1)
Learnt from: hardingjam
PR: rainlanguage/rain.orderbook#1594
File: packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte:0-0
Timestamp: 2025-04-05T13:16:58.971Z
Learning: In the DeploymentSteps component, the `checkingDeployment` state variable should be reset to false both after successful operations and error cases to ensure the deploy button returns to its normal state.
🔇 Additional comments (1)
packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte (1)

205-215: Improved error handling flow in deployment process.

The changes correctly streamline the error handling flow within the handleDeployButtonClick function. By removing what was likely a redundant null check after the try-catch block, error messages from Rust are now properly surfaced through the existing error handling mechanism.

The code also ensures checkingDeployment is properly reset to false both in the catch block (for errors) and after the try-catch block (for successful operations), which ensures the deploy button always returns to its normal state.


🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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
Copy Markdown
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a06bb53 and 0fcb7f6.

📒 Files selected for processing (2)
  • packages/ui-components/src/__tests__/DeploymentSteps.test.ts (3 hunks)
  • packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ui-components/src/__tests__/DeploymentSteps.test.ts

[error] 980-980: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: test
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: Deploy-Preview
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: git-clean
  • GitHub Check: test
🔇 Additional comments (5)
packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte (1)

208-210: Improved error handling with cleaner control flow.

The direct return of the DeploymentStepsError.catch result streamlines the error handling process, eliminating redundant code that was previously checking for errors in multiple places. This change makes the function more maintainable and easier to follow.

packages/ui-components/src/__tests__/DeploymentSteps.test.ts (4)

13-14: Good addition of necessary imports.

These imports properly support the new tests that verify the deployment transaction argument retrieval functionality.


28-30: Well-defined mock for getDeploymentTransactionArgs.

Appropriate mocking of the external dependency makes the test reliable and focused on the component's behavior rather than the implementation details of the dependency.


936-995: Thorough test for successful transaction args retrieval.

This test effectively validates that when deployment transaction arguments are successfully retrieved, the system correctly:

  1. Calls getDeploymentTransactionArgs with the expected parameters
  2. Presents the disclaimer modal to the user
  3. Opens the deployment modal with all the necessary information when confirmed

The test structure is clean and the assertions thoroughly check all aspects of the success path.

🧰 Tools
🪛 Biome (1.9.4)

[error] 980-980: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)


996-1054: Good error handling test case.

This test thoroughly verifies the error handling path when getDeploymentTransactionArgs fails:

  1. It confirms that the specific error message is displayed in the UI
  2. It verifies that the disclaimer modal is not called in error scenarios

This test provides important coverage for the updated error handling logic in the component, ensuring that errors are properly communicated to users.

Comment thread packages/ui-components/src/__tests__/DeploymentSteps.test.ts
Copy link
Copy Markdown
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0fcb7f6 and 182f645.

📒 Files selected for processing (1)
  • packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, test-js-bindings)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-legal)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-test)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-static)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-wasm-artifacts)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-rs-artifacts, true)
  • GitHub Check: standard-tests (ubuntu-latest, ob-rs-test, true)
  • GitHub Check: standard-tests (ubuntu-latest, rainix-sol-test)
  • GitHub Check: git-clean
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: build-tauri (ubuntu-22.04, true)
  • GitHub Check: test
  • GitHub Check: Deploy-Preview

Comment on lines 208 to +211
checkingDeployment = false;
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
}
if (!result) {
checkingDeployment = false;
DeploymentStepsError.catch(null, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
return;
return DeploymentStepsError.catch(e, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
}

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot Apr 5, 2025

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Improved error handling by directly returning the error from the catch block.

The code now properly surfaces the error from the Rust backend by directly returning the result of DeploymentStepsError.catch(). This ensures that error messages are properly propagated to the UI.

Note that checkingDeployment = false is now set both inside the catch block and immediately after it, which creates a redundancy when an exception is thrown. While this doesn't affect functionality, consider removing the duplicate assignment for cleaner code.

try {
  result = await getDeploymentTransactionArgs(gui, $account);
} catch (e) {
  checkingDeployment = false;
  return DeploymentStepsError.catch(e, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
}

-checkingDeployment = false;
📝 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
checkingDeployment = false;
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
}
if (!result) {
checkingDeployment = false;
DeploymentStepsError.catch(null, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
return;
return DeploymentStepsError.catch(e, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
}
try {
result = await getDeploymentTransactionArgs(gui, $account);
} catch (e) {
checkingDeployment = false;
return DeploymentStepsError.catch(e, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we need to reset the button even after successfully getting the args

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@hardingjam You're absolutely right! We need to ensure the button resets after successfully retrieving the args, not just when an error occurs.

The current code only resets checkingDeployment to false inside the catch block, but not after a successful execution path. This would leave the button in a loading state when everything goes well.

Here's how we should fix it:

try {
  result = await getDeploymentTransactionArgs(gui, $account);
} catch (e) {
  checkingDeployment = false;
  return DeploymentStepsError.catch(e, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
}

checkingDeployment = false; // Reset after successful retrieval

This ensures the button returns to normal state regardless of whether the operation succeeds or fails.

✏️ Learnings added
Learnt from: hardingjam
PR: rainlanguage/rain.orderbook#1594
File: packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte:0-0
Timestamp: 2025-04-05T13:16:58.812Z
Learning: In the DeploymentSteps component, the `checkingDeployment` state variable should be reset to false both after successful operations and error cases to ensure the deploy button returns to its normal state.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@hardyjosh hardyjosh enabled auto-merge April 5, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working webapp

Projects

None yet

2 participants