Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

[FLOSS P3] Kdb validate #4224

Merged
merged 23 commits into from
Jan 24, 2022
Merged

Conversation

flo91
Copy link
Collaborator

@flo91 flo91 commented Jan 12, 2022

Basics

Related issue: #3674

These points need to be fulfilled for every PR:

  • Short descriptions of your changes are in the release notes
    (added as entry in doc/news/_preparation_next_release.md which
    contains _(my name)_)
    Please always add something to the release notes.
  • Details of what you changed are in commit messages
    (first line should have module: short statement syntax)
  • References to issues, e.g. close #X, are in the commit messages.
  • The buildservers are happy. If not, fix in this order:
    • add a line in doc/news/_preparation_next_release.md
    • reformat the code with scripts/dev/reformat-all
    • make all unit tests pass
    • fix all memleaks
  • The PR is rebased with current master.

If you have any troubles fulfilling these criteria, please write
about the trouble as comment in the PR. We will help you.
But we cannot accept PRs that do not fulfill the basics.

Checklist

Check relevant points but please do not remove entries.
For docu fixes, spell checking, and similar none of these points below
need to be checked.

  • I added unit tests for my code
  • I fully described what my PR does in the documentation
    (not in the PR description)
  • I fixed all affected documentation
  • I added code comments, logging, and assertions as appropriate (see Coding Guidelines)
  • I updated all meta data (e.g. README.md of plugins and METADATA.ini)
  • I mentioned every code not directly written by me in THIRD-PARTY-LICENSES

Review

Reviewers will usually check the following:

Labels

If you are already Elektra developer:

  • Add the "work in progress" label if you do not want the PR to be reviewed yet.
  • Add the "ready to merge" label if the basics are fulfilled and you also
    say that everything is ready to be merged.

@flo91 flo91 added cm2022s for university course lang/cpp project2022w Suitable as project work in progress labels Jan 12, 2022
@flo91 flo91 changed the title [FLOSS P3] Kdb validate [FLOSS P3 - WIP!] Kdb validate Jan 12, 2022
@flo91 flo91 force-pushed the kdb_validate branch 2 times, most recently from 17480a0 to ae1ae3e Compare January 16, 2022 14:29
Copy link
Contributor

@markus2330 markus2330 left a comment

Choose a reason for hiding this comment

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

Very comprehensive work, looks very good to reach all points. 🚀 Please focus on reaching a mergable state.

## OPTIONS

- `-d`,`--debug`:
Give debug information or ask debug questions (in interactive mode).
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the interactive mode? There doesn't seem to be a -i option?

Copy link
Collaborator Author

@flo91 flo91 Jan 19, 2022

Choose a reason for hiding this comment

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

Thanks for reporting that mistake!
That was a leftover from a copy-paste of the manpage from another tool.
Gets fixed by commit c2ec7eb.

- `-d`,`--debug`:
Give debug information or ask debug questions (in interactive mode).
- `-f`, `--force`:
Force the action to be done.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Force the action to be done.
Force writing the configuration even on warnings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, good clarification!
Gets changed by commit c2ec7eb.

throw invalid_argument ("1 argument needed");
}

cout << "The given path was: " << cl.arguments[0] << endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Output only on debug (if at all). Probably more interesting is the name of the root key and not getting back exactly the given argument.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thx, I fixed it while adapting the ValidateCommand::execute() to use the new C++ error-classes.


if (cl.force)
{
cout << getFormattedInfoString (
Copy link
Contributor

Choose a reason for hiding this comment

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

again: only for -v.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed by commit 18edf39.

"The validation was stopped because of warnings "
"while getting the values!")
<< endl;
kdb.close ();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is done automatically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thx, I removed the statement.

* The warning is copied to make it independent from the source object. This way the same warning added to two different errors can be
* changed independently.
*
* An Error can contain 0 to n warnings.
Copy link
Contributor

Choose a reason for hiding this comment

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

A key can contain 0-n warnings. I would say that the error does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here we adhered to the concept that was established by the Error-Keys and also the highlevel-API (/src/libs/highlevel/elektra_error.c).
Therefore we designed an Error-class that can hold multiple Warnings, so a Key of the C-API with 0 or 1 errors and 0 to n warnings can be directly converted to an object of type Error and the behaviour is consistent with the highlevel-API.

I extended the comment to explain the concept a bit in commit c2ec7eb.

namespace errors
{

/* Not an error by itself, but a container for multiple warnings */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/* Not an error by itself, but a container for multiple warnings */
/* Not an warning by itself, but a container for multiple warnings */

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As I wrote in the previous message, an Error object can contain multiple Warnings so that an Error-key can directly be converted to a single C++ Error-object and to keep the behaviour consistent with the highlevel-API.
In commit c2ec7eb I extended the comment to explain the concept a bit more.



/* Concrete classes for the different Errors, based on the constants defined in /src/include/kdberrors.h */
class ResourceError : public Error
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this could even be in src/bindings/cpp/include/kdbexcept.hpp this would need some exception mapping in src/bindings/cpp/include/kdb.hpp, though. (extra work beyond original scope of project)

{
/*TODO: Decide if ordering of warnings should be considered for equality.
* Currently two errors are equal if they contain the same warnings (compared by member values),
* even if they have different orders in the internal vector.*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for the good feedback! 😀

Error* ErrorFactory::create(const std::string & type, const std::string & reason, const std::string & module,
const std::string & file, const std::string & mountPoint, const std::string & configFile, kdb::long_t line)
{
if (type == ELEKTRA_ERROR_RESOURCE || type == ELEKTRA_ERROR_RESOURCE_NAME)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would be the type sometimes the _NAME and sometimes not?

Copy link
Collaborator Author

@flo91 flo91 Jan 19, 2022

Choose a reason for hiding this comment

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

At the bottom of /src/include/kdberrors.h, for every introduced code four constants are defined:

#define DECLARE_ERROR_CODE(cname)                                                                                                          \
	extern const char * ELEKTRA_ERROR_##cname;                                                                                         \
	extern const char * ELEKTRA_ERROR_##cname##_NAME;                                                                                  \
                                                                                                                                           \
	extern const char * ELEKTRA_WARNING_##cname;                                                                                       \
	extern const char * ELEKTRA_WARNING_##cname##_NAME;                                                                                \
                                                                                                                                           \
	void elektraSetError##cname (Key * key, const char * file, const char * line, const char * module, const char * reason, ...);      \
	void elektraAddWarning##cname (Key * key, const char * file, const char * line, const char * module, const char * reason, ...);

DECLARE_ERROR_CODE (RESOURCE)
DECLARE_ERROR_CODE (OUT_OF_MEMORY)
DECLARE_ERROR_CODE (INSTALLATION)
DECLARE_ERROR_CODE (INTERNAL)
DECLARE_ERROR_CODE (INTERFACE)
DECLARE_ERROR_CODE (PLUGIN_MISBEHAVIOR)
DECLARE_ERROR_CODE (CONFLICTING_STATE)
DECLARE_ERROR_CODE (VALIDATION_SYNTACTIC)
DECLARE_ERROR_CODE (VALIDATION_SEMANTIC)

#undef DECLARE_ERROR_CODE

We designed the Factories so that the ELEKTRA_ERROR_##cname or ELEKTRA_ERROR_##cname##_NAME are valid parameters for creating an object of the appropriate type.

Should we change that so only the Code, but not the Description/_NAME is valid here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I do not think that _NAME should be anything external. It is only needed to render the error text. I created #4230

flo91 and others added 16 commits January 19, 2022 23:29
and do some improvements and bugfixes esp. regarding handling of
warnings
currently mostly a wrapper to the
implementation in /src/libs/highlevel/elektra_error.c
not finished or in a working state yet!
add iterator functionality for Warnings to Error class
…warnigns

Warnings get now cloned when they are stored in an Error object,
add further tests
add MountPoint and ConfigFile members,
add a PureWarning ErrorType for a dummy Error that only encapsulats Warnings,
add some testcode to /src/tools/kdb/validate.cpp
@flo91 flo91 marked this pull request as ready for review January 19, 2022 22:29
@flo91 flo91 changed the title [FLOSS P3 - WIP!] Kdb validate [FLOSS P3] Kdb validate Jan 19, 2022
flo91 added 3 commits January 20, 2022 13:24
libtools: make error and warning factories not instantiable (by deleting
their default constructors and destructors)
@markus2330 markus2330 merged commit 93c3f0d into ElektraInitiative:master Jan 24, 2022
@markus2330
Copy link
Contributor

Excellent job! 💖

@mpranj mpranj added this to the 0.9.9 milestone Mar 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cm2022s for university course lang/cpp project2022w Suitable as project ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants