class_docstr: Thrown if a command call fails.
  
  Note: Subclasses should override `to_str` rather than `__str__` because
  `to_str` is called directly in datalad.cli.main.
class_docstr_tok: ["Thrown","if","a","command","call","fails",".","Note",":","Subclasses","should","override","`","to_str","`","rather","than","`","__str__","`","because","`","to_str","`","is","called","directly","in","datalad.cli.main","."]
code: def to_str(self, include_output: bool = True) -> str:
      from datalad.utils import (
          ensure_unicode,
          join_cmdline,
      )
  
      to_str = "{}: ".format(self.__class__.__name__)
      cmd = self.cmd
      if cmd:
          to_str += "'{}'".format(
              # go for a compact, normal looking, properly quoted
              # command rendering if the command is in list form
              join_cmdline(cmd)
              if isinstance(cmd, list)
              else cmd
          )
      if self.code:
          to_str += " failed with exitcode {}".format(self.code)
      if self.cwd:
          # only if not under standard PWD
          to_str += " under {}".format(self.cwd)
      if self.msg:
          # typically a command error has no specific idea
          to_str += " [{}]".format(ensure_unicode(self.msg))
  
      if self.kwargs:
          to_str += " [info keys: {}]".format(
              ", ".join(self.kwargs.keys())
          )
  
          if "stdout_json" in self.kwargs:
              to_str += _format_json_error_messages(
                  self.kwargs["stdout_json"]
              )
  
      if not include_output:
          return to_str
  
      if self.stdout:
          to_str += " [out: '{}']".format(
              ensure_unicode(self.stdout).strip()
          )
      if self.stderr:
          to_str += " [err: '{}']".format(
              ensure_unicode(self.stderr).strip()
          )
  
      return to_str
  
file_path: datalad/datalad/runner/exception.py
imports: from __future__ import annotations
  import logging
  import os
  from collections import Counter
  from typing import Any, Optional
label_desc: Use image node_id 2 for calling the CommandError obj's underlying member method code with example usage: obj.to_str(include_output) and returns: to_str, to_str