Description
When adding an approleassignment to an existing Azure AD app, you can use the --appId option to reference the application by Application ID.

The command will search for the app and use the object ID of the app to add the role assignment.
If you make a mistake when using the --appId option. (for example you add the objectId in there instead of the appId) and the app cannot be found, the command throws an ugly exception, because a null-check is missing.
const servicePrincipalResult = await request.get<{ value: ServicePrincipal[] }>(getServicePrinciplesRequestOptions);
if (servicePrincipalResult.value.length > 1) {
throw 'More than one service principal found. Please use the appId or appObjectId option to make sure the right service principal is specified.';
}
objectId = servicePrincipalResult.value[0].id;
As you can see, the code searches for the app, it checks if multiple apps where returned, but it does not check if NO app was returned.
Steps to reproduce
Run the command in question with a wrong guid.
Expected results
An intelligible exception should be thrown saying that the app could not be found.
Actual results
An unintelligible exception is thrown.
Diagnostics
No response
CLI for Microsoft 365 version
6.1
nodejs version
14
Operating system (environment)
Windows
Shell
PowerShell
cli doctor
No response
Additional Info
No response
Description
When adding an approleassignment to an existing Azure AD app, you can use the
--appIdoption to reference the application by Application ID.The command will search for the app and use the object ID of the app to add the role assignment.
If you make a mistake when using the
--appIdoption. (for example you add the objectId in there instead of the appId) and the app cannot be found, the command throws an ugly exception, because a null-check is missing.As you can see, the code searches for the app, it checks if multiple apps where returned, but it does not check if NO app was returned.
Steps to reproduce
Run the command in question with a wrong guid.
Expected results
An intelligible exception should be thrown saying that the app could not be found.
Actual results
An unintelligible exception is thrown.
Diagnostics
No response
CLI for Microsoft 365 version
6.1
nodejs version
14
Operating system (environment)
Windows
Shell
PowerShell
cli doctor
No response
Additional Info
No response