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

show panel render error #4333

Open
wants to merge 1 commit into
base: py-panels-develop
Choose a base branch
from
Open

Conversation

imanjra
Copy link
Contributor

@imanjra imanjra commented May 1, 2024

What changes are proposed in this pull request?

Show panel render method error for python panel

How is this patch tested? If it is not, please explain why.

Using an example Python panel

class LayoutPanel(foo.Panel):
    @property
    def config(self):
        return foo.PanelOperatorConfig(name="python_panel_02_layout", label="PythonPanel0.2: Layout")

    def render(self, ctx):
        panel = types.Object()
        raise Exception("Error!")
        return types.Property(panel)

image

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features
    • Enhanced error handling in custom panel operations to improve stability and user experience.
  • Bug Fixes
    • Implemented optional chaining in property access to prevent application errors due to undefined or null values.

@imanjra imanjra requested a review from ritch May 1, 2024 00:55
Copy link
Contributor

coderabbitai bot commented May 1, 2024

Walkthrough

The changes made across the application aim to enhance robustness and user experience by introducing safer access patterns and improved error handling in custom panel functionalities. These updates ensure smoother interactions and increased fault tolerance in the application's operational flow.

Changes

File Path Summary of Changes
.../src/built-in-operators.ts Added nullish coalescing operator for safer property access and reformatted destructuring for readability.
.../src/useCustomPanelHooks.ts Modified useCustomPanelHooks to handle additional parameters in executing operators for panel state updates.

🐰✨🎉
A little hop and a code tweak,
Safer paths we do seek.
When errors loom, don't you fret,
Our panels are safer yet!
Celebrate, for bugs we check,
With every line, we perfect. 🌟
🐰✨🎉

Tip

New Features and Improvements

Review Settings

Introduced new personality profiles for code reviews. Users can now select between "Chill" and "Assertive" review tones to tailor feedback styles according to their preferences. The "Assertive" profile posts more comments and nitpicks the code more aggressively, while the "Chill" profile is more relaxed and posts fewer comments.

AST-based Instructions

CodeRabbit offers customizing reviews based on the Abstract Syntax Tree (AST) pattern matching. Read more about AST-based instructions in the documentation.

Community-driven AST-based Rules

We are kicking off a community-driven initiative to create and share AST-based rules. Users can now contribute their AST-based rules to detect security vulnerabilities, code smells, and anti-patterns. Please see the ast-grep-essentials repository for more information.

New Static Analysis Tools

We are continually expanding our support for static analysis tools. We have added support for biome, hadolint, and ast-grep. Update the settings in your .coderabbit.yaml file or head over to the settings page to enable or disable the tools you want to use.

Tone Settings

Users can now customize CodeRabbit to review code in the style of their favorite characters or personalities. Here are some of our favorite examples:

  • Mr. T: "You must talk like Mr. T in all your code reviews. I pity the fool who doesn't!"
  • Pirate: "Arr, matey! Ye must talk like a pirate in all yer code reviews. Yarrr!"
  • Snarky: "You must be snarky in all your code reviews. Snark, snark, snark!"

Revamped Settings Page

We have redesigned the settings page for a more intuitive layout, enabling users to find and adjust settings quickly. This change was long overdue; it not only improves the user experience but also allows our development team to add more settings in the future with ease. Going forward, the changes to .coderabbit.yaml will be reflected in the settings page, and vice versa.

Miscellaneous

  • Turn off free summarization: You can switch off free summarization of PRs opened by users not on a paid plan using the enable_free_tier setting.
  • Knowledge-base scope: You can now set the scope of the knowledge base to either the repository (local) or the organization (global) level using the knowledge_base setting. In addition, you can specify Jira project keys and Linear team keys to limit the knowledge base scope for those integrations.
  • High-level summary placement: You can now customize the location of the high-level summary in the PR description using the high_level_summary_placeholder setting (default @coderabbitai summary).
  • Revamped request changes workflow: You can now configure CodeRabbit to auto-approve or request changes on PRs based on the review feedback using the request_changes_workflow setting.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 1

Comment on lines +45 to +114
executeOperator(props.onLoad, { panel_id: panelId }, (result) => {
const { error: onLoadError } = result;
setPanelState((s) => ({ ...s, onLoadError, loaded: true }));
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling in asynchronous callbacks.

The current implementation of the error handling within the executeOperator callback does not account for potential exceptions that might be thrown by the setPanelState function. It's recommended to wrap the callback body in a try-catch block to handle such exceptions gracefully.

      executeOperator(props.onLoad, { panel_id: panelId }, (result) => {
        try {
          const { error: onLoadError } = result;
          setPanelState((s) => ({ ...s, onLoadError, loaded: true }));
+       } catch (error) {
+         console.error('Failed to update panel state:', error);
+       }
      });

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.

Suggested change
executeOperator(props.onLoad, { panel_id: panelId }, (result) => {
const { error: onLoadError } = result;
setPanelState((s) => ({ ...s, onLoadError, loaded: true }));
});
executeOperator(props.onLoad, { panel_id: panelId }, (result) => {
try {
const { error: onLoadError } = result;
setPanelState((s) => ({ ...s, onLoadError, loaded: true }));
} catch (error) {
console.error('Failed to update panel state:', error);
}
});

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: 3

Outside diff range and nitpick comments (5)
app/packages/operators/src/useCustomPanelHooks.ts (4)

Line range hint 16-26: Avoid using Function as a type for better type safety.

- onLoad?: Function;
- onChange?: Function;
- onUnLoad?: Function;
- onChangeCtx?: Function;
- onViewChange?: Function;
- onChangeView?: Function;
- onChangeDataset?: Function;
- onChangeCurrentSample?: Function;
- onChangeSelected?: Function;
- onChangeSelectedLabels?: Function;
- onChangeExtendedSelection?: Function;
+ onLoad?: () => void;
+ onChange?: () => void;
+ onUnLoad?: () => void;
+ onChangeCtx?: () => void;
+ onViewChange?: () => void;
+ onChangeView?: () => void;
+ onChangeDataset?: () => void;
+ onChangeCurrentSample?: () => void;
+ onChangeSelected?: () => void;
+ onChangeSelectedLabels?: () => void;
+ onChangeExtendedSelection?: () => void;

Line range hint 38-42: Specify explicit types instead of using any.

- panelState: any;
- handlePanelStateChange: Function;
- handlePanelStatePathChange: Function;
- data: any;
- panelSchema: any;
+ panelState: PanelStateType; // Define PanelStateType based on the expected structure
+ handlePanelStateChange: (newState: PanelStateType) => void;
+ handlePanelStatePathChange: (path: string, value: any, schema: SchemaType) => void; // Define SchemaType based on the expected structure
+ data: DataType; // Define DataType based on the expected structure
+ panelSchema: SchemaType;

Line range hint 48-48: Add missing dependencies to useEffect to ensure correct re-rendering.

-  }, [value, operator]);
+  }, [value, operator, triggerCtxChangedEvent]);

Line range hint 156-156: Specify explicit types instead of using any.

- function getPanelViewData(panelState: any): any {
+ function getPanelViewData(panelState: PanelStateType): DataType {
app/packages/operators/src/built-in-operators.ts (1)

Line range hint 908-908: Avoid using eval() due to security risks and performance issues.

- return eval(src.trim());
+ // Consider using a safer alternative to eval if possible, such as a dedicated parsing library or new Function() if absolutely necessary.
Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 39de11c and adb1b0b.
Files selected for processing (2)
  • app/packages/operators/src/built-in-operators.ts (2 hunks)
  • app/packages/operators/src/useCustomPanelHooks.ts (1 hunks)
Additional Context Used
Biome (40)
app/packages/operators/src/built-in-operators.ts (20)

875-875: This variable implicitly has the any type.


19-28: Some named imports are only used as types.


367-367: Don't use '{}' as a type.


421-421: Don't use '{}' as a type.


446-446: Don't use '{}' as a type.


468-468: Don't use '{}' as a type.


528-528: Don't use '{}' as a type.


616-616: Don't use '{}' as a type.


650-650: Don't use '{}' as a type.


738-738: Don't use '{}' as a type.


796-796: Don't use '{}' as a type.


812-812: Don't use '{}' as a type.


828-828: Don't use '{}' as a type.


844-844: Don't use '{}' as a type.


860-860: Don't use '{}' as a type.


899-899: Don't use '{}' as a type.


908-908: eval() exposes to security risks and performance issues.


919-919: Don't use '{}' as a type.


942-942: Don't use '{}' as a type.


998-998: Don't use '{}' as a type.

app/packages/operators/src/useCustomPanelHooks.ts (20)

38-38: Unexpected any. Specify a different type.


41-41: Unexpected any. Specify a different type.


42-42: Unexpected any. Specify a different type.


156-156: Unexpected any. Specify a different type.


16-16: Don't use 'Function' as a type.


17-17: Don't use 'Function' as a type.


18-18: Don't use 'Function' as a type.


19-19: Don't use 'Function' as a type.


20-20: Don't use 'Function' as a type.


21-21: Don't use 'Function' as a type.


22-22: Don't use 'Function' as a type.


23-23: Don't use 'Function' as a type.


24-24: Don't use 'Function' as a type.


25-25: Don't use 'Function' as a type.


26-26: Don't use 'Function' as a type.


39-39: Don't use 'Function' as a type.


40-40: Don't use 'Function' as a type.


48-48: This hook does not specify all of its dependencies: panelId


48-48: This hook does not specify all of its dependencies: triggerCtxChangedEvent


109-109: This hook does not specify all of its dependencies: panelState?.loaded

Path-based Instructions (2)
app/packages/operators/src/useCustomPanelHooks.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/operators/src/built-in-operators.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Additional comments not posted (2)
app/packages/operators/src/useCustomPanelHooks.ts (2)

111-114: Ensure proper error handling in asynchronous callbacks.


Line range hint 48-48: Ensure all dependencies are specified in useEffect.

@@ -108,8 +108,10 @@ export function useCustomPanelHooks(props: CustomPanelProps): CustomPanelHooks {

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure all dependencies are specified in useEffect.

-  }, [panelId, props.onLoad, props.onUnLoad]);
+  }, [panelId, props.onLoad, props.onUnLoad, panelState?.loaded]);

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.

Suggested change
useEffect(() => {
useEffect(() => {
}, [panelId, props.onLoad, props.onUnLoad, panelState?.loaded]);

Comment on lines +1005 to +1011
const {
params,
operator_uri,
on_success,
on_error,
on_cancel,
} = ctx.params;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling and user feedback in asynchronous operations.

+ if (result.error) {
+   console.error('Operation failed:', result.error);
+   // Optionally, provide user feedback here
+ }

Committable suggestion was skipped due low confidence.

@@ -871,7 +871,7 @@ function useUpdatePanelStatePartial(local?: boolean) {
targetParam = targetParam || targetPartial;
setTimeout(() => {
setPanelStateById(ctx.getCurrentPanelId(), (current = {}) => {
const currentCustomPanelState = current[targetPartial] || {};
const currentCustomPanelState = current?.[targetPartial] || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Specify explicit types to avoid implicit any.

- let updatedState;
+ let updatedState: CustomPanelStateType; // Define CustomPanelStateType based on the expected structure

Committable suggestion was skipped due low confidence.

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.

None yet

1 participant