Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make getPropertyAsInt throw #3146

Merged
merged 8 commits into from
Nov 18, 2024

Conversation

externl
Copy link
Member

@externl externl commented Nov 13, 2024

This PR updates getPropertyAsInt to throw a PropertyException in the event that the property cannot be converted to an integer.

@externl externl marked this pull request as ready for review November 13, 2024 18:58
@bernardnormier bernardnormier self-requested a review November 13, 2024 20:23
@externl externl requested a review from pepone November 13, 2024 20:26
@@ -82,15 +82,17 @@ namespace Ice
std::string getPropertyWithDefault(std::string_view key, std::string_view value) noexcept;

/**
* Get a property as an integer. If the property is not set, 0 is returned.
* Get a property as an integer. If the property is not set, 0 is returned. Throws PropertyException if
Copy link
Member

Choose a reason for hiding this comment

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

What the function throws belongs to the @throws tag, not the summary.


/**
* Get an Ice property as an integer. If the property is not set, its default value is returned.
* Get an Ice property as an integer. If the property is not set, its default value is returned. Throws
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

@@ -99,13 +101,14 @@ namespace Ice
int getIcePropertyAsInt(std::string_view key);

/**
* Get a property as an integer. If the property is not set, the given default value is returned.
* Get a property as an integer. If the property is not set, the given default value is returned. Throws
* PropertyException if the property value is not a valid integer.
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

@@ -165,15 +165,17 @@ public string getPropertyWithDefault(string key, string value)

/// <summary>
/// Get a property as an integer.
/// If the property is not set, 0 is returned.
/// If the property is not set, 0 is returned. Throws PropertyException if the property
Copy link
Member

Choose a reason for hiding this comment

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

The summary should not describe what the method throws.

Copy link
Member

Choose a reason for hiding this comment

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

Still have to move the exception docs to exception tag

@@ -215,6 +216,7 @@ public int getPropertyAsInt(String key) {
*
* @param key The property key.
* @return The property value interpreted as an integer, or the default value.
* @throws PropertyException Raised if the property value is not a valid integer.
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to document what we throw if the key doesn't designate a valid Ice property.

@@ -70,5 +70,15 @@ function run($args)
test($ex->getMessage() == "unknown Ice property: Ice.UnknownProperty");
}
echo "ok\n";

echo "testing that trying to read a non-numeric value as an int throws... ";
try {
Copy link
Member

Choose a reason for hiding this comment

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

The try block should not include the "arrange" part of the test.

@@ -101,5 +101,15 @@ def run(args)
end
puts "ok"

print "testing that trying to read a non-numeric value as an int throws... "
begin
properties = Ice.createProperties(args)
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@@ -34,14 +34,14 @@ public protocol Properties: AnyObject {
/// - parameter _: `String` The property key.
///
/// - returns: `Int32` - The property value interpreted as an integer.
Copy link
Member

Choose a reason for hiding this comment

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

Need to document exception.


/// Get an Ice property as an integer. If the property is not set,its default value is returned.
///
/// - parameter key: `String` The property key.
///
/// - returns: `Int32` - The property value interpreted as an integer, or the default value.
func getIcePropertyAsInt(_ key: String) -> Int32
func getIcePropertyAsInt(_ key: String) throws -> Int32
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

Copy link
Member

@pepone pepone left a comment

Choose a reason for hiding this comment

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

Seems you still have to update JavaScript

@externl externl requested a review from pepone November 15, 2024 14:54
@@ -165,15 +165,17 @@ public string getPropertyWithDefault(string key, string value)

/// <summary>
/// Get a property as an integer.
/// If the property is not set, 0 is returned.
/// If the property is not set, 0 is returned. Throws PropertyException if the property
Copy link
Member

Choose a reason for hiding this comment

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

Still have to move the exception docs to exception tag

/// </summary>
/// <param name="key">The property key.</param>
/// <returns>The property value interpreted as an integer.</returns>
public int getPropertyAsInt(string key) => getPropertyAsIntWithDefault(key, 0);

/// <summary>
/// Get an Ice property as an integer.
/// If the property is not set, its default value is returned.
/// If the property is not set, its default value is returned. Throws PropertyException if the property is not a
/// known Ice property or the value is not a valid integer.
Copy link
Member

Choose a reason for hiding this comment

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

ditto, move the exception docs to exception tag

@externl externl merged commit 892f92b into zeroc-ice:main Nov 18, 2024
19 checks passed
@externl externl deleted the make-getPropertyAsInt-throw branch November 18, 2024 15:25
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Dec 26, 2024
InsertCreativityHere pushed a commit to InsertCreativityHere/compiler-comparison that referenced this pull request Jan 1, 2025
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.

3 participants