Skip to content

Bug report: When adding an approleassignment to an existing app, you get an odd exception when the appId cannot be found. #4307

@martinlingstuyl

Description

@martinlingstuyl

Description

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

image

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions