MCPcopy Index your code
hub / github.com/cockroachdb/errors / RegisterTypeMigration

Function RegisterTypeMigration

errbase/migrations.go:94–112  ·  view source on GitHub ↗

This file provides the library with the ability to handle cases where an error type migrates, i.e. its package changes path or the type name is changed. There are several scenarios to contend with. Assuming the error type is initially called "foo", in version v1 of the code. Scenario 1: simple mig

(previousPkgPath, previousTypeName string, newType error)

Source from the content-addressed store, hash-verified

92// the last component of the package path can be different. This is
93// why they must be specified separately.
94func RegisterTypeMigration(previousPkgPath, previousTypeName string, newType error) {
95 prevKey := TypeKey(makeTypeKey(previousPkgPath, previousTypeName))
96 newKey := TypeKey(getFullTypeName(newType))
97
98 // Register the backward migration: make the encode function
99 // aware of the old name.
100 if f, ok := backwardRegistry[newKey]; ok {
101 panic(fmt.Errorf("migration to type %q already registered (from %q)", newKey, f))
102 }
103 backwardRegistry[newKey] = prevKey
104 // If any other key was registered as a migration from newKey,
105 // we'll forward those as well.
106 // This changes X -> newKey to X -> prevKey for every X.
107 for new, prev := range backwardRegistry {
108 if prev == newKey {
109 backwardRegistry[new] = prevKey
110 }
111 }
112}
113
114// registry used when encoding an error, so that the receiver observes
115// the original key. This maps new keys to old keys.

Calls 3

TypeKeyTypeAlias · 0.85
makeTypeKeyFunction · 0.85
getFullTypeNameFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…