Skip to content

Perfdata errors#116

Merged
RincewindsHat merged 6 commits into
masterfrom
perfdata_errors
Jun 20, 2024
Merged

Perfdata errors#116
RincewindsHat merged 6 commits into
masterfrom
perfdata_errors

Conversation

@RincewindsHat
Copy link
Copy Markdown
Member

No description provided.

Lorenz Kästle added 4 commits June 17, 2024 14:28
This patch changes the function signature of Performance data formatting
functions to return errors.
This is a preparation step to allow the rejection of certain values,
which are valid values for that data type, but not valid as measurements
@RincewindsHat
Copy link
Copy Markdown
Member Author

closes #115

@martialblog
Copy link
Copy Markdown
Member

Nice. I'll have a look at it later today

Comment thread perfdata/type.go Outdated
// Returns an eror in some known cases where the value of a data type does not
// represent a valid measurement, see the explanation for "formatNumeric" for
// perfdata values.
func (p Perfdata) String() (string, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't like that this is no longer implements the Stringer interface. https://pkg.go.dev/fmt#Stringer

I rather have the formatNumeric handle that and the Stringer interface be implemented, since it is more expectable when having a String() method on a struct.

Not sure how else we could or should communicate that NaN/Inf are not printed. Maybe just docs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see your point. I think I have an idea.

Copy link
Copy Markdown
Member Author

@RincewindsHat RincewindsHat Jun 18, 2024

Choose a reason for hiding this comment

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

I restored the behaviour of String by using the new functionality and just ignoring errors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Coolio. I'll have a look later.

RincewindsHat and others added 2 commits June 18, 2024 22:55
This commit restores the previous signature of String() for perfdata
by moving the functionality in a new method (which is also exported).
This new method validates the data and throws errors, the String()
method catches them and just returns the empty string then.
Copy link
Copy Markdown
Member

@martialblog martialblog left a comment

Choose a reason for hiding this comment

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

Can be merged.

We can still have a discussion on if and how to allow strings a values later

@RincewindsHat RincewindsHat merged commit 3ece825 into master Jun 20, 2024
@RincewindsHat RincewindsHat deleted the perfdata_errors branch June 20, 2024 12:27
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