okta-aws-cli-assume-role icon indicating copy to clipboard operation
okta-aws-cli-assume-role copied to clipboard

Empty role map throws java.util.NoSuchElementException

Open misterzero opened this issue 3 years ago • 0 comments

The following code threw this java.util.NoSuchElementException:

okta-aws awsdev sts get-caller-identity
Username: [email protected]
Password: 
Exception in thread "main" java.util.NoSuchElementException
	at java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:721)
	at java.base/java.util.LinkedHashMap$LinkedEntryIterator.next(LinkedHashMap.java:751)
	at java.base/java.util.LinkedHashMap$LinkedEntryIterator.next(LinkedHashMap.java:749)
	at com.okta.tools.helpers.RoleHelper.chooseAwsRoleToAssume(RoleHelper.java:106)
	at com.okta.tools.OktaAwsCliAssumeRole.doRequest(OktaAwsCliAssumeRole.java:133)
	at com.okta.tools.OktaAwsCliAssumeRole.run(OktaAwsCliAssumeRole.java:102)
	at com.okta.tools.WithOkta.main(WithOkta.java:30)

https://github.com/oktadeveloper/okta-aws-cli-assume-role/blob/7a47adbcd67004dfc27678efdf5d45e13b9df475/src/main/java/com/okta/tools/helpers/RoleHelper.java#L106

I need to figure out why I did not have any roles available, however it would save troubleshooting time to provide a more clear error message like:

} else if (roleIdpPairs.size() < 1) {
  throw new NoSuchElementException("No roles available for this user")
} else {
...

misterzero avatar Apr 14 '21 22:04 misterzero