Skip to content

Commit ff3fa97

Browse files
committed
fix(osgen): make errwrap catalogs functions to drop mutable globals
errwrap.Wrappers and errwrap.OperationWrappers were exported mutable package vars carrying //nolint:gochecknoglobals directives. Convert both to functions that return a fresh slice/map. This removes the gochecknoglobals findings honestly (no suppression), and makes the read-only catalogs immutable from a caller's perspective -- callers can no longer mutate the shared backing slice/map. The only consumers are in-package (For, sortedCanonical); update them to call the functions. Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent 2004cc0 commit ff3fa97

1 file changed

Lines changed: 100 additions & 97 deletions

File tree

cmd/osgen/errwrap/errwrap.go

Lines changed: 100 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -102,116 +102,118 @@ const (
102102
GroupSearchRelevanceGetStats = "search_relevance.get_stats"
103103
)
104104

105-
// Wrappers is the canonical order of wrapper schemas. Parallels the bit
105+
// Wrappers returns the canonical order of wrapper schemas. Parallels the bit
106106
// positions in errmask so a Wrappers index N corresponds to errmask bit
107-
// 1<<N.
108-
//
109-
//nolint:gochecknoglobals // const-ish read-only catalog
110-
var Wrappers = []string{
111-
WrapperBulkItems,
112-
WrapperSearchShards,
113-
WrapperWriteShards,
114-
WrapperBroadcastShards,
115-
WrapperNodeFailures,
116-
WrapperBulkByScrollFailures,
117-
WrapperTaskFailures,
118-
WrapperMultiSearchItems,
119-
WrapperMultiDocItems,
120-
WrapperSnapshotCreateShardFailures,
121-
WrapperSnapshotGetShardFailures,
122-
WrapperSimulateDocFailures,
123-
WrapperRankEvalFailures,
124-
WrapperIngestionShardFailures,
125-
WrapperPitNodeFailures,
107+
// 1<<N. Returning a fresh slice (rather than exporting a package var) keeps
108+
// the catalog immutable from a caller's perspective.
109+
func Wrappers() []string {
110+
return []string{
111+
WrapperBulkItems,
112+
WrapperSearchShards,
113+
WrapperWriteShards,
114+
WrapperBroadcastShards,
115+
WrapperNodeFailures,
116+
WrapperBulkByScrollFailures,
117+
WrapperTaskFailures,
118+
WrapperMultiSearchItems,
119+
WrapperMultiDocItems,
120+
WrapperSnapshotCreateShardFailures,
121+
WrapperSnapshotGetShardFailures,
122+
WrapperSimulateDocFailures,
123+
WrapperRankEvalFailures,
124+
WrapperIngestionShardFailures,
125+
WrapperPitNodeFailures,
126+
}
126127
}
127128

128-
// OperationWrappers is the hardcoded per-operation map: x-operation-group
129-
// (the spec's "Group" string -- see ir.Operation.Group) -> wrapper-schema
130-
// names that operation may surface.
129+
// OperationWrappers returns the hardcoded per-operation map:
130+
// x-operation-group (the spec's "Group" string -- see ir.Operation.Group) ->
131+
// wrapper-schema names that operation may surface.
131132
//
132133
// Every entry in this map is what would otherwise be the
133134
// `x-error-responses` array on the upstream operation. When the spec
134135
// gains a native extension, swap this lookup for one driven by the
135136
// parsed extension; the code in cmd/osgen/api_extract.go is the only
136-
// caller.
137-
//
138-
//nolint:gochecknoglobals // const-ish read-only catalog
139-
var OperationWrappers = map[string][]string{
140-
// _core
141-
// NOTE: bulk and bulk_stream also surface WriteShards (per-item replica
142-
// failures) per the spec proposal, but the wire shape lives inside
143-
// items[].error rather than at top-level _shards -- emit a dedicated
144-
// handler when we add per-item write inspection. Until then the
145-
// catalog records the wrapper so the user-facing bit is reserved.
146-
GroupBulk: {WrapperBulkItems},
147-
GroupBulkStream: {WrapperBulkItems},
148-
GroupSearch: {WrapperSearchShards},
149-
GroupScroll: {WrapperSearchShards},
150-
GroupSearchTemplate: {WrapperSearchShards},
151-
GroupCreatePIT: {WrapperSearchShards},
152-
GroupCount: {WrapperSearchShards},
153-
GroupIndex: {WrapperWriteShards},
154-
GroupCreate: {WrapperWriteShards},
155-
GroupUpdate: {WrapperWriteShards},
156-
GroupDelete: {WrapperWriteShards},
157-
GroupReindex: {WrapperBulkByScrollFailures},
158-
GroupUpdateByQuery: {WrapperBulkByScrollFailures},
159-
GroupDeleteByQuery: {WrapperBulkByScrollFailures},
160-
GroupMSearch: {WrapperSearchShards, WrapperMultiSearchItems},
161-
GroupMSearchTemplate: {WrapperSearchShards, WrapperMultiSearchItems},
162-
GroupMGet: {WrapperMultiDocItems},
163-
GroupMTermvectors: {WrapperMultiDocItems},
164-
GroupRankEval: {WrapperRankEvalFailures},
165-
GroupGetAllPITs: {WrapperPitNodeFailures},
166-
167-
// indices
168-
GroupIndicesRefresh: {WrapperBroadcastShards},
169-
GroupIndicesFlush: {WrapperBroadcastShards},
170-
GroupIndicesForceMerge: {WrapperBroadcastShards},
171-
GroupIndicesClearCache: {WrapperBroadcastShards},
172-
GroupIndicesValidateQuery: {WrapperBroadcastShards},
173-
GroupIndicesSegments: {WrapperBroadcastShards},
174-
GroupIndicesStats: {WrapperBroadcastShards},
175-
GroupIndicesUpgrade: {WrapperBroadcastShards},
176-
GroupIndicesDataStreamsStats: {WrapperBroadcastShards},
177-
178-
// cluster / nodes / dangling
179-
GroupClusterStats: {WrapperNodeFailures},
180-
GroupNodesInfo: {WrapperNodeFailures},
181-
GroupNodesStats: {WrapperNodeFailures},
182-
GroupNodesUsage: {WrapperNodeFailures},
183-
GroupNodesReloadSecureSettings: {WrapperNodeFailures},
184-
GroupDanglingIndicesList: {WrapperNodeFailures},
185-
186-
// tasks
187-
GroupTasksList: {WrapperTaskFailures},
188-
GroupTasksCancel: {WrapperTaskFailures},
189-
190-
// snapshot
191-
GroupSnapshotCreate: {WrapperSnapshotCreateShardFailures},
192-
GroupSnapshotGet: {WrapperSnapshotGetShardFailures},
193-
194-
// ingest / ingestion
195-
GroupIngestSimulate: {WrapperSimulateDocFailures},
196-
GroupIngestionGetState: {WrapperBroadcastShards},
197-
GroupIngestionPause: {WrapperIngestionShardFailures},
198-
GroupIngestionResume: {WrapperIngestionShardFailures},
199-
200-
// asynchronous_search (plugin)
201-
GroupAsynchronousSearchSearch: {WrapperSearchShards},
202-
GroupAsynchronousSearchGet: {WrapperSearchShards},
203-
204-
// search_relevance (plugin)
205-
GroupSearchRelevanceGetNodeStats: {WrapperNodeFailures},
206-
GroupSearchRelevanceGetStats: {WrapperNodeFailures},
137+
// caller. Returning a fresh map (rather than exporting a package var) keeps
138+
// the catalog immutable from a caller's perspective.
139+
func OperationWrappers() map[string][]string {
140+
return map[string][]string{
141+
// _core
142+
// NOTE: bulk and bulk_stream also surface WriteShards (per-item replica
143+
// failures) per the spec proposal, but the wire shape lives inside
144+
// items[].error rather than at top-level _shards -- emit a dedicated
145+
// handler when we add per-item write inspection. Until then the
146+
// catalog records the wrapper so the user-facing bit is reserved.
147+
GroupBulk: {WrapperBulkItems},
148+
GroupBulkStream: {WrapperBulkItems},
149+
GroupSearch: {WrapperSearchShards},
150+
GroupScroll: {WrapperSearchShards},
151+
GroupSearchTemplate: {WrapperSearchShards},
152+
GroupCreatePIT: {WrapperSearchShards},
153+
GroupCount: {WrapperSearchShards},
154+
GroupIndex: {WrapperWriteShards},
155+
GroupCreate: {WrapperWriteShards},
156+
GroupUpdate: {WrapperWriteShards},
157+
GroupDelete: {WrapperWriteShards},
158+
GroupReindex: {WrapperBulkByScrollFailures},
159+
GroupUpdateByQuery: {WrapperBulkByScrollFailures},
160+
GroupDeleteByQuery: {WrapperBulkByScrollFailures},
161+
GroupMSearch: {WrapperSearchShards, WrapperMultiSearchItems},
162+
GroupMSearchTemplate: {WrapperSearchShards, WrapperMultiSearchItems},
163+
GroupMGet: {WrapperMultiDocItems},
164+
GroupMTermvectors: {WrapperMultiDocItems},
165+
GroupRankEval: {WrapperRankEvalFailures},
166+
GroupGetAllPITs: {WrapperPitNodeFailures},
167+
168+
// indices
169+
GroupIndicesRefresh: {WrapperBroadcastShards},
170+
GroupIndicesFlush: {WrapperBroadcastShards},
171+
GroupIndicesForceMerge: {WrapperBroadcastShards},
172+
GroupIndicesClearCache: {WrapperBroadcastShards},
173+
GroupIndicesValidateQuery: {WrapperBroadcastShards},
174+
GroupIndicesSegments: {WrapperBroadcastShards},
175+
GroupIndicesStats: {WrapperBroadcastShards},
176+
GroupIndicesUpgrade: {WrapperBroadcastShards},
177+
GroupIndicesDataStreamsStats: {WrapperBroadcastShards},
178+
179+
// cluster / nodes / dangling
180+
GroupClusterStats: {WrapperNodeFailures},
181+
GroupNodesInfo: {WrapperNodeFailures},
182+
GroupNodesStats: {WrapperNodeFailures},
183+
GroupNodesUsage: {WrapperNodeFailures},
184+
GroupNodesReloadSecureSettings: {WrapperNodeFailures},
185+
GroupDanglingIndicesList: {WrapperNodeFailures},
186+
187+
// tasks
188+
GroupTasksList: {WrapperTaskFailures},
189+
GroupTasksCancel: {WrapperTaskFailures},
190+
191+
// snapshot
192+
GroupSnapshotCreate: {WrapperSnapshotCreateShardFailures},
193+
GroupSnapshotGet: {WrapperSnapshotGetShardFailures},
194+
195+
// ingest / ingestion
196+
GroupIngestSimulate: {WrapperSimulateDocFailures},
197+
GroupIngestionGetState: {WrapperBroadcastShards},
198+
GroupIngestionPause: {WrapperIngestionShardFailures},
199+
GroupIngestionResume: {WrapperIngestionShardFailures},
200+
201+
// asynchronous_search (plugin)
202+
GroupAsynchronousSearchSearch: {WrapperSearchShards},
203+
GroupAsynchronousSearchGet: {WrapperSearchShards},
204+
205+
// search_relevance (plugin)
206+
GroupSearchRelevanceGetNodeStats: {WrapperNodeFailures},
207+
GroupSearchRelevanceGetStats: {WrapperNodeFailures},
208+
}
207209
}
208210

209211
// For looks up the wrappers declared for a given operation group. Returns
210212
// nil for operations with no partial-failure surface area. The returned
211213
// slice is sorted (canonical order from Wrappers) so codegen output stays
212214
// deterministic across runs.
213215
func For(group string) []string {
214-
raw, ok := OperationWrappers[group]
216+
raw, ok := OperationWrappers()[group]
215217
if !ok {
216218
return nil
217219
}
@@ -223,8 +225,9 @@ func sortedCanonical(in []string) []string {
223225
if len(in) == 0 {
224226
return nil
225227
}
226-
idx := make(map[string]int, len(Wrappers))
227-
for i, w := range Wrappers {
228+
wrappers := Wrappers()
229+
idx := make(map[string]int, len(wrappers))
230+
for i, w := range wrappers {
228231
idx[w] = i
229232
}
230233
out := make([]string, len(in))

0 commit comments

Comments
 (0)