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 error when parsing an invalid command with shell-quote #571

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

sejas
Copy link
Member

@sejas sejas commented Sep 27, 2024

Fixes: https://github.com/Automattic/dotcom-forge/issues/9280

Proposed Changes

  • It wraps shell-quote parse to avoid returning an error in useIsValidWpCliInline

Testing Instructions

  • Run npm start
  • Go to the assistant
  • Click in How do I create a store
  • Observe the message is sent and the response rendered
  • You can go to trunk and observe the error when trying to render the same response.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@sejas sejas self-assigned this Sep 27, 2024
@sejas sejas requested review from wojtekn, katinthehatsite and a team September 27, 2024 15:22
Copy link
Contributor

@wojtekn wojtekn left a comment

Choose a reason for hiding this comment

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

It fixes the issue for me.

} )
.filter( Boolean ) as string[];
} catch ( error ) {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know what command made it fail?

Copy link
Member Author

@sejas sejas Sep 27, 2024

Choose a reason for hiding this comment

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

Yes!, it was when we tried to parse JS code as bash command. In my case:

command import { store, getContext } from '@wordpress/interactivity';

store( "myPlugin", {
    actions: {
        toggle: () => {
            const context = getContext();
            context.isOpen = !context.isOpen;
        },
    },
    callbacks: {
        logIsOpen: () => {
            const { isOpen } = getContext();
            console.log( `Is open: ${ isOpen }` );
        }
    },
});

and

import { store, getContext } from '@wordpress/interactivity';

store( "myPlugin", {
    actions: {
        toggle: () => {
            const context = getContext();
            context.isOpen = !context.isOpen;
        },
    },
    callbacks: {
        logIsOpen: () => {
            const { isOpen } = getContext();
            console.log( `Is open: ${ isOpen }` );
        }
    },
});

BTW, I'll change the initial prompt as a follow up. Because it matches store with wp-data instead of a woocommerce store.

@sejas sejas merged commit e57d932 into trunk Sep 27, 2024
10 checks passed
@sejas sejas deleted the fix/parse-error-wpcli branch September 27, 2024 15:39
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.

2 participants