Bug 355262

Summary: setErrorCode function does not let set a custom error code
Product: [Frameworks and Libraries] frameworks-kauth Reporter: Azael Avalos <coproscefalo>
Component: generalAssignee: kdelibs bugs <kdelibs-bugs-null>
Status: RESOLVED INTENTIONAL    
Severity: normal CC: coproscefalo, sitter
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Proposed fix

Description Azael Avalos 2015-11-12 17:55:46 UTC
When using KAuth::ActionReply class, the setErrorCode function is used to set a custom error code whenever the ActionReply object is set to type HelperErrorType, however, such function does not allow to set such custom error code and instead asks for one of the (libabry internal) error codes designated for when the type is KAuthErrorType.

Reproducible: Always

Steps to Reproduce:
1. Instantiate a KAuth::ActionReply object: KAuth::ActionReply reply,
2. Set the reply object to an empty HelperErrorType: reply = KAuth::ActionReply::HelperErrorReply();
3. Set the custom error code: reply.setErrorCode(myerrorcode);

Actual Results:  
Compiler error, as the setErrorCode function receives a KAuth::ActionReply::Error instead of a uint.

Expected Results:  
The setErrorCode function should receive a uint instead of a KAuth::ActionReply::Error so the code can compile.

The KAuthActionReply header contains an example of the described usage:
 @code
 ActionReply MyHelper::read(QVariantMap args)
 {
     ActionReply reply;
     QString filename = args["filename"].toString();
     QFile file(filename);
     if (!file.open(QIODevice::ReadOnly)) {
        reply = ActionReply::HelperErrorReply;
        reply.setErrorCode(file.error());

        return reply;
     }

     QTextStream stream(&file);
     QString contents;
     stream >> contents;
     reply.data()["contents"] = contents;

     return reply;
 }
 @endcode

But the code itself does not honor such functionality, so two things might be broken here, the function itself or the example provided in the header file.
Comment 1 Azael Avalos 2015-12-12 16:32:37 UTC
Created attachment 96017 [details]
Proposed fix
Comment 2 Harald Sitter 2020-09-05 15:17:06 UTC
I'm pretty sure the way this is meant to work is that you make a helper error reply and set whatever you want in the data of the reply. That is 100% flexible.
We do not treat enums as int in modern c++ so changing this is a firm no.