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

Throw error when SP URL is null #6012

Open
milanholemans opened this issue May 1, 2024 · 6 comments · May be fixed by #6044
Open

Throw error when SP URL is null #6012

milanholemans opened this issue May 1, 2024 · 6 comments · May be fixed by #6044

Comments

@milanholemans
Copy link
Contributor

milanholemans commented May 1, 2024

While testing a command I used a variable to store my site URL so it didn't clutter my command args too much. However, I was getting a strange error as shown below:

image

This error was due to the fact that I made a typo and --webUrl was null (because the variable I specified didn't exist).

This is because the validator we are using is as follows:

isValidSharePointUrl(url: string): boolean | string {
if (!url) {
return false;
}
if (url.indexOf('https://') !== 0) {
return `${url} is not a valid SharePoint Online site URL`;
}
else {
return true;
}
},

In the command (and other commands) we validate it like this:

const isValidSharePointUrl: boolean | string = validation.isValidSharePointUrl(args.options.webUrl);
if (isValidSharePointUrl !== true) {
return isValidSharePointUrl;
}

Shouldn't we output an error message when the value is null? The current error Error: false doesn't help at all.

@milanholemans milanholemans added enhancement needs peer review Needs second pair of eyes to review the spec or PR labels May 1, 2024
@Adam-it
Copy link
Contributor

Adam-it commented May 4, 2024

yes we should 😉.
also we should double-check this behavior in other shells. in bash probably this would be just an empty string. I don't know about other.
luckily we usually use isValidSharePointUrl for this validation so I hope this would only require us to do some refactoring in this single place

@Adam-it
Copy link
Contributor

Adam-it commented May 4, 2024

I even got something worse 😉
image

@milanholemans
Copy link
Contributor Author

milanholemans commented May 4, 2024

I even got something worse 😉 image

Yes, that's the importance of #initTypes right now. We should type all options as much as possible. If we don't, Minimist will decide what type a variable is. When you pass --webUrl null, it translates to --webUrl which is a flag. In that case, it will get the value true, and .indexOf is not a function of a boolean value. We have not paid enough attention to this in the past.

@Adam-it
Copy link
Contributor

Adam-it commented May 4, 2024

awww right.
image

Bummer, what if we create an issue to fix this problem globally and add the missing #initTypes?

@milanholemans
Copy link
Contributor Author

milanholemans commented May 4, 2024

Bummer, what if we create an issue to fix this problem globally and add the missing #initTypes?

It's a lot of work since this applies to every single option in every single command. The same thing will happen when you run entra m365group get --id $iDoNotExist.
I know this is a known issue, and I try to fix this gradually in every command I work on/review.

The good news is, with the implementation of ZOD, this will all be fixed because every option will be typed automatically. So I suggest that we just deal with it right now. Otherwise, we have to fix this in 90% of all commands right now, and we still have to implement ZOD in every command, which will fix it anyway. So that's kind of (a lot of) double work.

@Jwaegebaert Jwaegebaert added help wanted and removed needs peer review Needs second pair of eyes to review the spec or PR labels May 6, 2024
@Saurabh7019
Copy link
Contributor

Can I work on it?

Saurabh7019 added a commit to Saurabh7019/cli-microsoft365 that referenced this issue May 10, 2024
@Saurabh7019 Saurabh7019 linked a pull request May 10, 2024 that will close this issue
Saurabh7019 added a commit to Saurabh7019/cli-microsoft365 that referenced this issue May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants