Skip to content

Commit 17c05eb

Browse files
Revert back to static list
1 parent 3a2d86b commit 17c05eb

File tree

2 files changed

+4
-82
lines changed

2 files changed

+4
-82
lines changed

packages/cli-kit/src/public/node/error-handler.test.ts

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
errorHandler,
3-
cleanStackFrameFilePath,
4-
addBugsnagMetadata,
5-
sendErrorToBugsnag,
6-
computeAllowedSliceNames,
7-
registerCleanBugsnagErrorsFromWithinPlugins,
8-
} from './error-handler.js'
1+
import {errorHandler, cleanStackFrameFilePath, addBugsnagMetadata, sendErrorToBugsnag} from './error-handler.js'
92
import * as metadata from './metadata.js'
103
import {ciPlatform, cloudEnvironment, isUnitTest, macAddress} from './context/local.js'
114
import {mockAndCaptureOutput} from './testing/output.js'
@@ -224,33 +217,7 @@ describe('sends errors to Bugsnag', () => {
224217
expect(mockOutput.debug()).toMatch('Error reporting to Bugsnag: Error: Bugsnag is down')
225218
})
226219

227-
test('logs and suppresses when allowed slice names not initialized', async () => {
228-
// Reset module state to ensure ALLOWED_SLICE_NAMES is undefined
229-
vi.resetModules()
230-
231-
await metadata.addSensitiveMetadata(() => ({
232-
commandStartOptions: {startTime: Date.now(), startCommand: 'app dev', startArgs: []},
233-
}))
234-
235-
const mockOutput = mockAndCaptureOutput()
236-
237-
const res = await sendErrorToBugsnag(new Error('boom'), 'unexpected_error')
238-
expect(res.reported).toEqual(false)
239-
expect(mockOutput.debug()).toMatch(
240-
'Error reporting to Bugsnag: Error: Internal error: allowed slice names not initialized.',
241-
)
242-
})
243-
244220
test('attaches custom metadata with allowed slice_name when startCommand is present', async () => {
245-
// Initialize allowed slice names to include 'app' using a mock config
246-
await registerCleanBugsnagErrorsFromWithinPlugins({
247-
// Minimal shape required by the function
248-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
249-
commands: [{id: 'app:dev'}] as any,
250-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
251-
plugins: new Map() as any,
252-
} as unknown as any)
253-
254221
await metadata.addSensitiveMetadata(() => ({
255222
commandStartOptions: {startTime: Date.now(), startCommand: 'app dev', startArgs: []},
256223
}))
@@ -275,14 +242,6 @@ describe('sends errors to Bugsnag', () => {
275242
})
276243

277244
test('defaults slice_name to cli when first word not allowed', async () => {
278-
// Initialize allowed slice names to known set that does not include 'version'
279-
await registerCleanBugsnagErrorsFromWithinPlugins({
280-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
281-
commands: [{id: 'app:dev'}] as any,
282-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
283-
plugins: new Map() as any,
284-
} as unknown as any)
285-
286245
await metadata.addSensitiveMetadata(() => ({
287246
commandStartOptions: {startTime: Date.now(), startCommand: 'version', startArgs: []},
288247
}))
@@ -293,16 +252,3 @@ describe('sends errors to Bugsnag', () => {
293252
expect(lastBugsnagEvent!.addMetadata).toHaveBeenCalledWith('custom', {slice_name: 'cli'})
294253
})
295254
})
296-
297-
describe('computeAllowedSliceNames', () => {
298-
test('derives first tokens from command IDs', () => {
299-
const names = computeAllowedSliceNames({
300-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
301-
commands: [{id: 'app:build'}, {id: 'theme:pull'}, {id: 'version'}, {id: undefined as any}] as any,
302-
} as unknown as any)
303-
expect(names.has('app')).toBe(true)
304-
expect(names.has('theme')).toBe(true)
305-
expect(names.has('version')).toBe(true)
306-
expect(names.has('store')).toBe(false)
307-
})
308-
})

packages/cli-kit/src/public/node/error-handler.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,9 @@ import StackTracey from 'stacktracey'
2121
import Bugsnag, {Event} from '@bugsnag/js'
2222
import {realpath} from 'fs/promises'
2323

24-
// Allowed slice names for error analytics grouping. This is populated from the
25-
// loaded OCLIF config at runtime.
26-
let ALLOWED_SLICE_NAMES: Set<string> | undefined
27-
28-
export function computeAllowedSliceNames(config: Interfaces.Config): Set<string> {
29-
const names = new Set<string>()
30-
const commands = (config.commands ?? []) as Array<{id?: string}>
31-
for (const cmd of commands) {
32-
// Command IDs are typically colon-separated (e.g. app:build). We take the first token.
33-
const id = (cmd as unknown as {id?: string}).id
34-
if (!id) continue
35-
const first = id.split(':')[0]?.trim()
36-
if (first) names.add(first)
37-
}
38-
return names
39-
}
40-
41-
export function initializeAllowedSliceNames(config: Interfaces.Config): void {
42-
ALLOWED_SLICE_NAMES = computeAllowedSliceNames(config)
43-
}
24+
// Allowed slice names for error analytics grouping.
25+
// Hardcoded list per product slices to keep analytics consistent.
26+
const ALLOWED_SLICE_NAMES = new Set<string>(['app', 'theme', 'hydrogen', 'store'])
4427

4528
export async function errorHandler(
4629
error: Error & {exitCode?: number | undefined},
@@ -151,11 +134,6 @@ export async function sendErrorToBugsnag(
151134
const {commandStartOptions} = metadata.getAllSensitiveMetadata()
152135
const {startCommand} = commandStartOptions ?? {}
153136
if (startCommand) {
154-
if (!ALLOWED_SLICE_NAMES) {
155-
throw new Error(
156-
'Internal error: allowed slice names not initialized. Ensure registerCleanBugsnagErrorsFromWithinPlugins() ran.',
157-
)
158-
}
159137
const firstWord = startCommand.trim().split(/\s+/)[0] ?? 'cli'
160138
const sliceName = ALLOWED_SLICE_NAMES.has(firstWord) ? firstWord : 'cli'
161139
event.addMetadata('custom', {slice_name: sliceName})
@@ -216,8 +194,6 @@ export function cleanStackFrameFilePath({
216194
*
217195
*/
218196
export async function registerCleanBugsnagErrorsFromWithinPlugins(config: Interfaces.Config): Promise<void> {
219-
// Update allowed slice names dynamically based on loaded commands
220-
initializeAllowedSliceNames(config)
221197
// Bugsnag have their own plug-ins that use this private field
222198

223199
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)