git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv1 1/3] git-p4: raise exceptions from p4CmdList based on error from p4 server

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 5, 2018, 09:54 UTC
Message-ID
<CAPig+cQTTY8wc4d=4jV8GxHDOjF7xk1vjA62JS6s4Zr0uXiegg@mail.gmail.com>
In-Reply-To
<20180605091350.14476-2-luke@diamand.org>
On Tue, Jun 5, 2018 at 5:14 AM Luke Diamand <luke@diamand.org> wrote:
Show 26 quoted lines
> This change lays some groundwork for better handling of rowcount errors
> from the server, where it fails to send us results because we requested
> too many.
>
> It adds an option to p4CmdList() to return errors as a Python exception.
>
> The exceptions are derived from P4Exception (something went wrong),
> P4ServerException (the server sent us an error code) and
> P4RequestSizeException (we requested too many rows/results from the
> server database).
>
> This makes makes the code that handles the errors a bit easier.
>
> The default behavior is unchanged; the new code is enabled with a flag.
>
> Signed-off-by: Luke Diamand <luke@diamand.org>
> ---
> diff --git a/git-p4.py b/git-p4.py
> @@ -566,10 +566,30 @@ def isModeExec(mode):
> +class P4ServerException(Exception):
> +    """ Base class for exceptions where we get some kind of marshalled up result from the server """
> +    def __init__(self, exit_code, p4_result):
> +        super(P4ServerException, self).__init__(exit_code)
> +        self.p4_result = p4_result
> +        self.code = p4_result[0]['code']
> +        self.data = p4_result[0]['data']

The subsequent patches never seem to access any of these fields, so it's difficult to judge whether it's worthwhile having 'code' and 'data' bits split out like this.

Show 12 quoted lines
> @@ -616,9 +636,25 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False):
>      if exitCode != 0:
> -        entry = {}
> -        entry["p4ExitCode"] = exitCode
> -        result.append(entry)
> +        if errors_as_exceptions:
> +            if len(result) > 0:
> +                data = result[0].get('data')
> +                if data:
> +                    m = re.search('Too many rows scanned \(over (\d+)\)', data)
> +                    if not m:
> +                        m = re.search('Request too large \(over (\d+)\)', data)
Does 'p4' localize these error messages?
Show 11 quoted lines
> +                    if m:
> +                        limit = int(m.group(1))
> +                        raise P4RequestSizeException(exitCode, result, limit)
> +
> +                raise P4ServerException(exitCode, result)
> +            else:
> +                raise P4Exception(exitCode)
> +        else:
> +            entry = {}
> +            entry["p4ExitCode"] = exitCode
> +            result.append(entry)
Previous: Luke DiamandNext: Luke Diamand
Message 3 of 10 in “[PATCHv1 0/3] git-p4: improvements to p4 "blocking"”
  1. Luke DiamandJun 5, 2018
  2. 1/3 git-p4: raise exceptions from p4CmdList based on error from p4 serverLuke Diamand, Jun 5, 2018
  3. Eric SunshineJun 5, 2018
  4. Luke DiamandJun 5, 2018
  5. Eric SunshineJun 5, 2018
  6. Luke DiamandJun 5, 2018
  7. Luke DiamandJun 8, 2018
  8. 2/3 git-p4: narrow the scope of exceptions caught when parsing an intLuke Diamand, Jun 5, 2018
  9. 3/3 git-p4: auto-size the blockLuke Diamand, Jun 5, 2018
  10. Eric SunshineJun 5, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.