Skip to content

Conversation

lmolkova
Copy link

Logging + exceptions improvements:

  • log exceptions where they are thrown
  • don't catch-log-rethrow the same exceptions
  • use key-value-pairs instead of string concat

@Copilot Copilot AI review requested due to automatic review settings May 21, 2025 02:44
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR focuses on improving logging practices across the KV v2 codebase by replacing ad hoc try‐catch blocks and manual exception constructions with a consistent usage of key‐value logging and utility methods. The key changes include using LOGGER.throwableAtError().log(...) in place of LOGGER.logThrowableAsError() and adopting Objects.requireNonNull for null checks.

Reviewed Changes

Copilot reviewed 44 out of 44 changed files in this pull request and generated no comments.

File Description
sdk/keyvault-v2/azure-security-keyvault-keys/.../Aes128Kw.java Updated key validation to pass LOGGER for consistent error logging.
sdk/keyvault-v2/azure-security-keyvault-keys/.../CryptographyClientBuilder.java Replaced try-catch error wrapping with direct LOGGER.throwableAtError() calls.
sdk/keyvault-v2/azure-security-keyvault-keys/.../KeyClientBuilder.java Replaced manual null-checks with Objects.requireNonNull.
(Numerous certificate and administration files) Standardized logging exceptions and null checks, removed redundant try-catch blocks and improved error messages with key-value metadata.
Comments suppressed due to low confidence (3)

sdk/keyvault-v2/azure-security-keyvault-keys/src/main/java/com/azure/v2/security/keyvault/keys/cryptography/CryptographyClientBuilder.java:151

  • Verify that replacing the catch-log-rethrow pattern with direct logging using throwableAtError() produces the intended exception type and message consistency across the API.
throw LOGGER.throwableAtError().log("Key caching cannot be disabled when using a JSON Web Key.", IllegalStateException::new);

sdk/keyvault-v2/azure-security-keyvault-administration/src/main/java/com/azure/v2/security/keyvault/administration/KeyVaultAdministrationUtil.java:192

  • [nitpick] Consider adding more contextual information (such as method or parameter names) to the log message to help diagnose unsupported operation types more easily.
throw logger.throwableAtError().addKeyValue("operationType", operation == null ? null : operation.getClass().getCanonicalName()).log(UnsupportedOperationException::new);

sdk/keyvault-v2/azure-security-keyvault-keys/src/main/java/com/azure/v2/security/keyvault/keys/cryptography/implementation/Aes128Kw.java:29

  • Ensure that passing the LOGGER instance to the validation method is safe and that the method properly handles a null logger if it could occur in other contexts.
CryptographyUtils.validate(key, KEY_SIZE_IN_BYTES, LOGGER);

Copy link
Member

@vcolin7 vcolin7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most things look great, just left some comments :)

Copy link
Member

@vcolin7 vcolin7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lmolkova lmolkova merged commit fab8069 into Azure:main May 28, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants