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

     1  #!/bin/sh
     2  
     3  set -eu
     4  
     5  # This script will generate a mapping from condition names to error codes.
     6  # It will not perform any cleanup, so some manual post-processing may be
     7  # necessary for duplicate 'Error' strings, capitalizing initialisms and
     8  # acronyms, 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})    .    ([A-Z_]+)[[:space:]]+([a-z_]+).*$|"\3": {"\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|' > errcodes.generated