Skip to content

Conversation

marcschier
Copy link
Contributor

@marcschier marcschier commented Oct 13, 2025

Proposed changes

Describe the changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.

Related Issues

  • Fixes #

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply. You can also fill these out after creating the PR.

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ marcschier
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

codecov bot commented Oct 13, 2025

Codecov Report

❌ Patch coverage is 27.36099% with 823 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.51%. Comparing base (ca43b64) to head (9de8742).

Files with missing lines Patch % Lines
Stack/Opc.Ua.Core/Types/Utils/TypeInfo.cs 21.95% 92 Missing and 4 partials ⚠️
Stack/Opc.Ua.Core/Stack/Types/FilterEvaluator.cs 2.73% 71 Missing ⚠️
Libraries/Opc.Ua.Client/Session/Session.cs 10.60% 59 Missing ⚠️
Stack/Opc.Ua.Core/Stack/State/NodeState.cs 19.40% 52 Missing and 2 partials ⚠️
Stack/Opc.Ua.Core/Stack/Nodes/Node.cs 0.00% 51 Missing ⚠️
Libraries/Opc.Ua.Server/Diagnostics/AuditEvents.cs 0.00% 25 Missing ⚠️
Stack/Opc.Ua.Core/Types/BuiltIn/NodeId.cs 4.76% 20 Missing ⚠️
...Ua.Client/Session/Factory/DefaultSessionFactory.cs 26.08% 17 Missing ⚠️
...pc.Ua.Gds.Server.Common/ApplicationsNodeManager.cs 39.28% 10 Missing and 7 partials ⚠️
Stack/Opc.Ua.Core/Types/Utils/ServiceResult.cs 55.26% 17 Missing ⚠️
... and 81 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3264      +/-   ##
==========================================
- Coverage   57.81%   57.51%   -0.30%     
==========================================
  Files         365      365              
  Lines       79423    79838     +415     
  Branches    13870    13874       +4     
==========================================
+ Hits        45920    45922       +2     
- Misses      29338    29704     +366     
- Partials     4165     4212      +47     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcschier marcschier marked this pull request as ready for review October 14, 2025 10:16
@marcschier marcschier requested a review from Copilot October 14, 2025 11:49
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 checking bounds for values used in switch statements and includes various Roslyn analyzer cleanup improvements across the codebase.

Key changes include:

  • Enhanced switch statement handling with proper bounds checking and default cases
  • Replacement of manual exception construction with ServiceResultException.Unexpected() utility method
  • Addition of missing default cases in switch statements to handle unexpected enum values
  • Code cleanup and modernization following Roslyn analyzer suggestions

Reviewed Changes

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

Show a summary per file
File Description
Tests/Opc.Ua.Server.Tests/ServerFixtureUtils.cs Replaced manual ServiceResultException construction with ServiceResultException.Unexpected()
Tests/Opc.Ua.Core.Tests/Types/Encoders/JsonValidationData.cs Converted switch statement to switch expression with bounds checking
Tests/Opc.Ua.Core.Tests/Types/Encoders/EncoderCommon.cs Added default case with bounds checking in decode method
Tests/Opc.Ua.Core.Tests/Types/Encoders/EncodeableTests.cs Added missing default cases and exception documentation
Tests/Opc.Ua.Core.Tests/Types/BuiltIn/BuiltInTests.cs Enhanced NodeId comparison with proper default case handling
Stack/Opc.Ua.Core/Types/Utils/Utils.cs Reorganized switch statements and replaced manual exception construction
Stack/Opc.Ua.Core/Types/Utils/TypeInfo.cs Added bounds checking and proper default cases for BuiltInType handling
Stack/Opc.Ua.Core/Types/Utils/ServiceResultException.cs Added Unexpected() utility method for consistent exception handling
Stack/Opc.Ua.Core/Types/Encoders/*.cs Enhanced encoder/decoder classes with proper bounds checking
Libraries/Opc.Ua.Server/Session/Session.cs Added bounds checking for RequestType enum values
Comments suppressed due to low confidence (4)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

case BuiltInType.Integer:
case BuiltInType.UInteger:
throw new ServiceResultException(
StatusCodes.BadEncodingError,
Copy link
Contributor

@romanett romanett Oct 14, 2025

Choose a reason for hiding this comment

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

is this true?
UInteger ->Type '{0}' is not allowed in an Variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original behavior is in place, this threw before on default, but default: now throws unexpected because e.g. (BuiltInType)333 should be an unexpected error (or bad code). I was thinking that it should still throw EncodingError, but on encoding path it at least is bad code, on decoding path it is debateable because we read ints from wire, and it could result in default: to enter. Now we do not get a decoderError, but BadUnexpected. However - the latter can be handled centrally better, because it is really "unexpected" if this was encoded with our encoders.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually all unhandled cases threw on exit at the bottom of the method.

Updated the handling of diagnostic information by changing `ReturnDiagnostics` from `DiagnosticsMasks.All` to `DiagnosticsMasks.SymbolicIdAndText` across multiple files to reduce verbosity. Enhanced error handling by including `StatusCodes.BadNoCommunication` in retry conditions for `ServiceResultException`. Removed redundant `Session.ReturnDiagnostics` setting in `GlobalDiscoveryServerClient.cs`. Fixed a typo in XML documentation in `ClientBase.cs`. Ensured consistent diagnostic settings in `ClientFixture.cs` and related files.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="useDefaults">if set to <c>true</c> use defaults].</param>
/// <param name="useDefaults">if set to <c>true</c> use defaults.</param>
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldnt we document use defaults has no effect any more

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be overridden (method is virtual). So I would keep it as is. But hope we are ok with setting diagnostics mask for all requests even if a requestHeader was passed as long as that was passed with None, correct? Because you can set the ReturnDiagnostics on the client, and if you set it there to None you would get the default behavior. And it is by default None.

@romanett
Copy link
Contributor

@marcschier thanks for investigating the CI Issues. Can you put the final fixes into a separate PR for better separation?

@marcschier
Copy link
Contributor Author

@marcschier thanks for investigating the CI Issues. Can you put the final fixes into a separate PR for better separation?

@romanett - I am waiting whether I can get tests to pass more stably with this one, and then sort out separating this and stability into 2 PRs. I used this one to incrementally debug because it was the biggest and furthest one ahead compared to the other 2 PR, which now are merged, so yes, makes sense.

@marcschier marcschier marked this pull request as draft October 17, 2025 08:46
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.

5 participants