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

Raise error for enum creation from invalid string values #1300

Merged
merged 4 commits into from
Aug 26, 2024

Conversation

parthosa
Copy link
Collaborator

Fixes #887: This PR updates the fromstring() method for Enum creation to raise a ValueError for invalid input strings. Previously, it would silently returned None, which could lead to unexpected behaviour if not handled by the caller.

Changes

class EnumeratedType:

  • fromstring() now raises a ValueError for invalid strings.
  • Changed fromstring() return type to EnumeratedType.
  • Added get_default() to return a default value. This is implemented by the subclasses.

Signed-off-by: Partho Sarthi <[email protected]>
@parthosa parthosa added bug Something isn't working user_tools Scope the wrapper module running CSP, QualX, and reports (python) labels Aug 20, 2024
@parthosa parthosa self-assigned this Aug 20, 2024
'Accepted options are: [%s].\n\t'
'Falling-back to default filter: %s',
arg_val, Utils.gen_joined_str(' | ', available_filters),
QualFilterApp.tostring(selected_filter))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this behavior the same? Previously, this block does not raise exception even if arg_val is not QualFilterApp, but after this changes, it could.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This check seemed redundant to me. QualFilterApp argument is provided by the user, and our argument validator (argprocessor) would validates these inputs as first step. If there are invalid values, we will terminate early.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This code was initially there because we had the legacy CLI that was not doing the same initialization as spark_rapids.
There pros-cons removing it:

  • pros: it is redundant
  • cons: Starting the qualification tool without going through the argProcessor will bypass all those checks.

Copy link
Collaborator Author

@parthosa parthosa Aug 24, 2024

Choose a reason for hiding this comment

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

Yes, in that case, it will bypass those checks. If caller provides invalid value of QualFilterApp, the tool would crash instead of silently continuing with the default value. I think this should be the right behavior. I agree this differs from the original behavior.

Copy link
Collaborator

@cindyyuanjiang cindyyuanjiang left a comment

Choose a reason for hiding this comment

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

Thanks @parthosa!

@parthosa parthosa merged commit e4e1b0d into NVIDIA:dev Aug 26, 2024
14 checks passed
@parthosa parthosa deleted the spark-rapids-tools-887 branch August 26, 2024 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working user_tools Scope the wrapper module running CSP, QualX, and reports (python)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Fix handling of fromstring() for invalid enums
3 participants