Skip to content

Development -> Master#39

Merged
prestoncraw merged 2 commits intomasterfrom
development
Jan 26, 2026
Merged

Development -> Master#39
prestoncraw merged 2 commits intomasterfrom
development

Conversation

@prestoncraw
Copy link
Contributor

No description provided.

Comment on lines +224 to +228
)
{
// Set dictionaries
SetSignalTypes();
SetCompanies();
SetCompanies();

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

Copilot Autofix

AI about 2 months ago

In general, to fix “generic catch clause” issues, identify which exceptions the try block is expected to throw in normal error conditions and catch only those types; let other exceptions bubble up. If there is a requirement to be very defensive, you can still add a narrow “last resort” catch around very specific infrastructure exceptions, or rethrow unknown ones.

For this method, the risky operations are the database operations and configuration usage: constructing AdoDataConnection with ConfigSettings.Instance, creating TableOperations<Measurement>, and calling QueryRecordWhere. These are likely to throw DataException, InvalidOperationException, or potentially ConfigurationErrorsException (or ConfigurationException depending on framework) in expected error scenarios. We should:

  • Replace catch (Exception ex) with one or more specific catches (e.g., DataException, InvalidOperationException) that log and return null.
  • Optionally add a final catch (Exception ex) that logs and then rethrows, but that would change behavior (currently it swallows everything), so we should avoid that.
  • Since the existing code intentionally swallows for robustness, the least intrusive change is to catch the primary data/config exceptions explicitly and keep the logging + null return. This narrows the catch while preserving external behavior for the common failure modes.

We only need to change the catch block around lines 167–171 in GuessBaseKV inside MeasurementExpressionParser.cs. No new imports are strictly required if DataException is already available via System.Data (which is imported at line 24). We can add an additional catch (InvalidOperationException ex) without new imports as it is in System.

Suggested changeset 1
src/Gemstone.Timeseries/Model/MeasurementExpressionParser.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Gemstone.Timeseries/Model/MeasurementExpressionParser.cs b/src/Gemstone.Timeseries/Model/MeasurementExpressionParser.cs
--- a/src/Gemstone.Timeseries/Model/MeasurementExpressionParser.cs
+++ b/src/Gemstone.Timeseries/Model/MeasurementExpressionParser.cs
@@ -164,11 +164,16 @@
                     Measurement? record = measurementTable.QueryRecordWhere("SignalReference = {0}", SignalReference.ToString(deviceAcronym, SignalKind.Magnitude, 1));
                     return record?.PointTag;
                 }
-                catch (Exception ex)
+                catch (DataException ex)
                 {
                     Logger.SwallowException(ex, $"Failed while looking up first phasor tag associated with device '{deviceAcronym}'");
                     return null;
                 }
+                catch (InvalidOperationException ex)
+                {
+                    Logger.SwallowException(ex, $"Failed while looking up first phasor tag associated with device '{deviceAcronym}'");
+                    return null;
+                }
             });
         }
 
EOF
@@ -164,11 +164,16 @@
Measurement? record = measurementTable.QueryRecordWhere("SignalReference = {0}", SignalReference.ToString(deviceAcronym, SignalKind.Magnitude, 1));
return record?.PointTag;
}
catch (Exception ex)
catch (DataException ex)
{
Logger.SwallowException(ex, $"Failed while looking up first phasor tag associated with device '{deviceAcronym}'");
return null;
}
catch (InvalidOperationException ex)
{
Logger.SwallowException(ex, $"Failed while looking up first phasor tag associated with device '{deviceAcronym}'");
return null;
}
});
}

Copilot is powered by AI and may make mistakes. Always verify output.
@prestoncraw prestoncraw merged commit 8dd654a into master Jan 26, 2026
3 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