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

💡 [Feature]: Support debug option #282

Open
Adam-it opened this issue Jul 28, 2024 · 7 comments
Open

💡 [Feature]: Support debug option #282

Adam-it opened this issue Jul 28, 2024 · 7 comments
Assignees
Labels
⭐ enhancement New feature or request 💪 good first issue Good for newcomers hacktoberfest 👨‍💻work in progress I am working on it
Milestone

Comments

@Adam-it
Copy link
Contributor

Adam-it commented Jul 28, 2024

🎯 Aim of the feature

Based on the problem we had in issue #278 it is not the first time that running local instance of CLI for M365, and related commands in debug, gave some answers on what could be the problem. This is some problem as the user needs to install CLI for M365 locally to make the double check which in general is not needed for this Toolkit to work.

The idea is to:

  1. Add a VS Code setting to the extension, maybe a checkbox like 'run CLI commands in debug'
    image

  2. Setting this would add the --debug option to each CLI for M365 command and will show their output in the VS Code extension output logs. We should add the debug option when any CLI command is executed in this methods

    private static async tryExecuteCommand(command: string, output: string | undefined = 'text', args?: any): Promise<CommandOutput> {

@Adam-it Adam-it added ⭐ enhancement New feature or request ✏️prototype labels Jul 28, 2024
@Adam-it Adam-it added this to the v3.X milestone Jul 28, 2024
@Adam-it Adam-it self-assigned this Jul 28, 2024
@Adam-it Adam-it added 💪 good first issue Good for newcomers 🙏 help wanted Open for contributors and removed ✏️prototype labels Jul 29, 2024
@Adam-it Adam-it removed their assignment Jul 29, 2024
@Adam-it Adam-it modified the milestones: v3.X, v4.X Sep 8, 2024
@DevPio
Copy link
Contributor

DevPio commented Sep 24, 2024

I would like to work on this problem

@Adam-it Adam-it added 👨‍💻work in progress I am working on it and removed 🙏 help wanted Open for contributors labels Sep 24, 2024
@Adam-it
Copy link
Contributor Author

Adam-it commented Sep 24, 2024

I would like to work on this problem

All yours.
Please keep in mind this issue participates in Hacktoberfest event so if you want this PR to count towards this event please be sure to open the PR during October (not sooner and not later 👍)

@DevPio
Copy link
Contributor

DevPio commented Sep 29, 2024

I noticed that when I set the debug flag to true and then switch it back to false, the command responses still behave as if they are in debug mode. Do you know of any way to reset or clear the command responses when switching the flag back to false? From what I’ve researched so far, it seems like there isn’t anything that directly addresses this. Could you help me with this?

Another thing I noticed is that when entering debug mode, many outputs are directed to stderr. Most of these outputs are not actual errors, but since they fill stderr, there are validations in the code that treat any output in stderr as an error, preventing the flow from continuing. This happens, for example, during the deploy stage.

image

Could you guide me on how to proceed? I would like to help with this task.

@Adam-it
Copy link
Contributor Author

Adam-it commented Sep 29, 2024

I noticed that when I set the debug flag to true and then switch it back to false, the command responses still behave as if they are in debug mode. Do you know of any way to reset or clear the command responses when switching the flag back to false? From what I’ve researched so far, it seems like there isn’t anything that directly addresses this. Could you help me with this?

The way it works is that the debug is a flag. So it does not matter if we pass true or false as long as we add --debug then CLI will use this option to present debug info.
Just check it out when I run come CLI for M365 command in terminal passing --debug false. As you see I still get the debug info.
image

So in order not to get debug info we may not pass --debug at all to the command. Same kind of case we already have in this extension where we dynamically create the list of options that will be passed to the command

const commandOptions: any = {};
if (input.name) {
commandOptions.name = input.name;
}
if (input.branch) {
commandOptions.branchName = input.branch;
}

Another thing I noticed is that when entering debug mode, many outputs are directed to stderr. Most of these outputs are not actual errors, but since they fill stderr, there are validations in the code that treat any output in stderr as an error, preventing the flow from continuing. This happens, for example, during the deploy stage.

This I did not figure out when prototyping this issue. Sorry for that.
CLI for Microsoft 365 have many configs https://pnp.github.io/cli-microsoft365/user-guide/configuring-cli
And one of it is errorOutput which allows to define if errors should be written to stdout or stderr. We could use that and set the config to sprint all errors to stdout instead. But this is kinda tricky as this setting may also modify the config of CLI for M365 someone might have already installed on the local machine outside of SPFx Toolkit.
So to sum up it is an option we may use but not the most (as of now) secure way. I will need to think about that 🤔.
Another way is we may just avoid error handling in SPFx Toolkit when debug setting is set 🤔, we are trying to debug SPFx Toolkit to get more error info right? This setting is suppose to show errors to try to get more info about a problem that might occur in SPFx Toolkit. This does make sense right

@DevPio
Copy link
Contributor

DevPio commented Oct 2, 2024

The issue is that after enabling the debug flag and then removing it, the responses in debug mode seem to persist. I followed the approach you suggested in the code. I believe we could go ahead with your suggestion to disable error validation during debugging. However, the problem seems to be that there's some form of caching happening. After entering and exiting debug mode, even when the flag is no longer passed, the debug responses still appear.

@Adam-it
Copy link
Contributor Author

Adam-it commented Oct 2, 2024

@DevPio do you have this on some branch on your fork? Could I have a check at the code?

@DevPio
Copy link
Contributor

DevPio commented Oct 3, 2024

Yes, I have this on a branch of my fork. You can check the code here: issue-282 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement New feature or request 💪 good first issue Good for newcomers hacktoberfest 👨‍💻work in progress I am working on it
Projects
None yet
Development

No branches or pull requests

2 participants