Skip to content

chore(examples): wrap file I/O errors with context#3141

Closed
marythought wants to merge 8 commits into
mainfrom
feat/dspx-2479
Closed

chore(examples): wrap file I/O errors with context#3141
marythought wants to merge 8 commits into
mainfrom
feat/dspx-2479

Conversation

@marythought
Copy link
Copy Markdown
Contributor

Summary

  • encrypt.go: wrap os.Create error to include the output file path
  • decrypt.go: wrap os.ReadDir and os.Open errors to include the file/directory path

Bare errors from these calls gave no indication of which file failed or what operation was attempted, making permission errors and similar issues difficult to diagnose.

Test plan

  • go test ./examples/... passes
  • golangci-lint run ./examples/... passes (pre-existing deprecation warning in examples.go is unrelated)

🤖 Generated with Claude Code

marythought and others added 7 commits March 9, 2026 09:44
Adds an integration test verifying that when using the Keycloak ERS,
subject mapping selectors must match the Keycloak user object structure
rather than raw JWT claim names. Custom Keycloak user attributes are
nested under `.attributes.<name>[]` in the resolved user object, so a
selector like `.department` will not match even when the JWT contains
`"department": "Finance"`. The correct selector is `.attributes.department[]`.

This test was motivated by a community discussion (orgs/opentdf/discussions/3115)
where a user experienced decryption failures due to this mismatch. The test
spins up a real Keycloak container, creates a user with a custom attribute,
and asserts both the correct and incorrect selector behaviors explicitly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
Addresses code review feedback by splitting the two subject mapping
assertions into t.Run sub-tests for clearer output and more granular
test results.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…havior

Documents that `.department` matches when ERS is configured with
mode: "claims" (entity is JWT private claims), whereas the correct
selector for Keycloak ERS (default) is `.attributes.department[]`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Expand TestClaimsERSSubjectMapping to cover both multi-valued OFF
  (string claim → .department) and multi-valued ON (array claim →
  .department[]) mapper configurations
- Add nolint:unparam to buildAttributeSubjectMapping so the parameter
  remains available for future callers with different FQNs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace manual setupKeycloakContainer + extended 60s retry block +
initializeKeycloakClient + createTestRealm calls with a single
adapter.SetupTestData call, matching the pattern used in
TestKeycloakEntityResolutionV2.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
Bare os.Open/os.Create/os.ReadDir errors gave no indication of which
file failed or what operation was attempted. Wrap with fmt.Errorf so
errors like "permission denied" include the file path and operation.

Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
@marythought marythought requested a review from a team as a code owner March 11, 2026 20:53
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on improving the diagnostic capabilities of file I/O operations within the examples directory by adding contextual information to returned errors, making it easier to identify the specific file or operation that failed. Additionally, it introduces new integration tests for the Entity Resolution Service, clarifying how subject mapping selectors interact with different entity structures (JWT claims vs. Keycloak user objects).

Highlights

  • Improved Error Context: Enhanced error messages for file I/O operations in decrypt.go and encrypt.go by wrapping os.ReadDir, os.Open, and os.Create errors with contextual information, including file paths.
  • New Integration Tests for Entity Resolution Service: Introduced new integration tests for the Entity Resolution Service (ERS) to verify subject mapping behavior in both 'claims' mode and 'Keycloak' mode, clarifying how selectors interact with different entity structures.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • examples/cmd/decrypt.go
    • Wrapped os.ReadDir error with directory path context.
    • Wrapped os.Open errors with file path context.
  • examples/cmd/encrypt.go
    • Wrapped os.Create error with output file path context.
  • service/entityresolution/integration/claims_attributes_test.go
    • Added TestClaimsERSSubjectMapping to verify claims-mode ERS subject mapping.
  • service/entityresolution/integration/keycloak_attributes_test.go
    • Added TestKeycloakUserAttributeSubjectMapping to verify Keycloak-mode ERS subject mapping.
Activity
  • The pull request was generated using Claude Code.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Error, vague and bare, Context added, path made clear, Debugging light.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces two distinct sets of changes. The first, as described, wraps file I/O errors in the example command-line tools with additional context, which improves error diagnostics. The second, larger change adds new integration tests for the Entity Resolution Service (ERS) subject mapping functionality. These tests clarify and verify the behavior of subject mapping selectors for both 'claims' mode and the default 'keycloak' mode. While the error wrapping is a good improvement and the new tests are valuable for documenting and ensuring the correctness of the subject mapping feature, it would be better to split these unrelated changes into separate pull requests for clarity and easier review, as the current PR title and description are misleading.

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 165.202874ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 94.478852ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 382.979007ms
Throughput 261.11 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 38.963446576s
Average Latency 387.867899ms
Throughput 128.33 requests/second

@github-actions
Copy link
Copy Markdown
Contributor

These tests are unrelated to this PR and belong in a separate change.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 185.053158ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 93.659417ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 376.449769ms
Throughput 265.64 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 39.268626356s
Average Latency 391.429153ms
Throughput 127.33 requests/second

@github-actions
Copy link
Copy Markdown
Contributor

marythought added a commit to opentdf/docs that referenced this pull request Mar 12, 2026
## Summary
- Adds File Permission Errors section to
`getting-started/managing-platform` troubleshooting — covers Docker
volume ownership mismatches, unreadable `/etc/resolv.conf`/`/etc/hosts`,
and install directory permissions. Documents the `"server misbehaving"`
gRPC error as a common symptom.
- Adds File Permission Errors section to `sdks/troubleshooting` — covers
SDK-level file I/O errors with cross-reference to the platform guide
- Adds home directory writability check to `check.sh`
- Adds Linux file permission troubleshooting callout to the quickstart
"Need Help?" section

Platform examples to be merged in:
opentdf/platform#3141

## Test plan
- [ ] Verify surge preview renders new troubleshooting sections in both
pages
- [ ] Confirm anchor link
`/getting-started/managing-platform#file-permission-errors-linux`
resolves correctly
- [ ] Run `check.sh` and confirm new home directory check appears in
output

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

4 similar comments
@github-actions
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants