github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/pgwire/pgcode/generate.sh (about)

     1  #!/bin/sh
     2  
     3  set -eu
     4  
     5  # This script will generate a list of error codes. It will not perform
     6  # any cleanup, so some manual post-processing may be necessary for
     7  # duplicate 'Error' strings, capitalizing initialisms and acronyms,
     8  # and fixing Golint errors.
     9  sed '/^\s*$/d' errcodes.txt |
    10  sed '/^#.*$/d' |
    11  sed -E 's|^(Section.*)$|// \1|' |
    12  sed -E 's|^([A-Z0-9]{5})    .    ERRCODE_([A-Z_]+).*$|\2 = MakeCode("\1")|' |
    13  # Postgres uses class 58 just for external errors, but we've extended it with some errors
    14  # internal to the cluster (inspired by DB2).
    15  sed -E 's|// Section: Class 58 - System Error \(errors external to PostgreSQL itself\)|// Section: Class 58 - System Error|' |
    16  awk '{$1=tolower($1); print $0}' |
    17  perl -pe 's/(^|_)./uc($&)/ge;s/_//g' > errcodes.generated