#50719 Issue 50634 - Fix CLI error parsing for non-string values
Closed 3 years ago by spichugi. Opened 4 years ago by spichugi.
spichugi/389-ds-base fix-errors-str  into  master

file modified
+1 -1
@@ -143,7 +143,7 @@ 

          if args and args.json:

              sys.stderr.write(json.dumps(msg))

          else:

-             log.error("Error: %s" % " - ".join(msg.values()))

+             log.error("Error: %s" % " - ".join(str(val) for val in msg.values()))

          result = False

  

      disconnect_instance(inst)

file modified
+1 -1
@@ -76,7 +76,7 @@ 

      except Exception as e:

          log.debug(e, exc_info=True)

          msg = format_error_to_dict(e)

-         log.error("Error: %s" % " - ".join(msg.values()))

+         log.error("Error: %s" % " - ".join(str(val) for val in msg.values()))

          result = False

  

      # Done!

file modified
+1 -1
@@ -129,7 +129,7 @@ 

      except Exception as e:

          log.debug(e, exc_info=True)

          msg = format_error_to_dict(e)

-         log.error("Error: %s" % " - ".join(msg.values()))

+         log.error("Error: %s" % " - ".join(str(val) for val in msg.values()))

          result = False

      disconnect_instance(inst)

  

file modified
+1 -1
@@ -133,7 +133,7 @@ 

      except Exception as e:

          log.debug(e, exc_info=True)

          msg = format_error_to_dict(e)

-         log.error("Error: %s" % " - ".join(msg.values()))

+         log.error("Error: %s" % " - ".join(str(val) for val in msg.values()))

          result = False

  

      disconnect_instance(inst)

@@ -422,6 +422,8 @@ 

      # We should fix the code here after the issue is fixed

      errmsg = str(exception)

      try:

+         # The function literal_eval parses the string and returns only if it's a literal.

+         # Also, the code is never executed. So there is no reason for a security risk.

          msg = ast.literal_eval(errmsg)

      except Exception:

          msg = {'desc': errmsg}

Bug Description: Sometimes the error message has int values and
it makes ' - '.join() function to fail.

Fix Description: Use a list comprehension to change the dict values to str.

https://pagure.io/389-ds-base/issue/50634

Reviewed by: ?

I'm merging this as I am about to do a upstream build...

Pull-Request has been merged by mreynolds

4 years ago

Thanks! I've cherry-picked the code to 1.4.0 and 1.4.1

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/3774

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago