@@ -154,7 +154,7 @@ export class OutputError extends CliError {
154154}
155155
156156const DEFAULT_CONTEXT_ALTERNATIVES = [
157- "Run from a directory with a Sentry-configured project " ,
157+ "Run from a directory with a Sentry DSN in source code or .env files " ,
158158 "Set SENTRY_ORG and SENTRY_PROJECT (or SENTRY_DSN) environment variables" ,
159159 "Run 'sentry org list' to find your organization slug" ,
160160 "Run 'sentry project list <org>/' to find project slugs" ,
@@ -169,22 +169,36 @@ const DEFAULT_CONTEXT_ALTERNATIVES = [
169169 * @param note - Optional informational context (e.g., "Found 2 DSN(s) that could not be resolved").
170170 * Rendered as a separate "Note:" section after alternatives. Use this for diagnostic
171171 * information that explains what the CLI tried — keep alternatives purely actionable.
172+ * @param isAutoDetect - When true, the headline explains that auto-detection was attempted
173+ * and failed rather than stating the value "is required". Callers that omit `alternatives`
174+ * (using defaults) trigger this automatically via the {@link ContextError} constructor.
172175 * @returns Formatted multi-line error message
173176 */
174177function buildContextMessage (
175178 resource : string ,
176179 command : string ,
177180 alternatives : string [ ] ,
178- note ?: string
181+ options ?: { note ?: string ; isAutoDetect ?: boolean }
179182) : string {
183+ const { note, isAutoDetect } = options ?? { } ;
180184 // Compound resources ("X and Y") need plural grammar
181185 const isPlural = resource . includes ( " and " ) ;
182- const lines = [
183- `${ resource } ${ isPlural ? "are" : "is" } required.` ,
184- "" ,
185- `Specify ${ isPlural ? "them" : "it" } using:` ,
186- ` ${ command } ` ,
187- ] ;
186+ const pronoun = isPlural ? "them" : "it" ;
187+
188+ const lines = isAutoDetect
189+ ? [
190+ `Could not auto-detect ${ resource . toLowerCase ( ) } .` ,
191+ "" ,
192+ `Provide ${ pronoun } explicitly:` ,
193+ ` ${ command } ` ,
194+ ]
195+ : [
196+ `${ resource } ${ isPlural ? "are" : "is" } required.` ,
197+ "" ,
198+ `Specify ${ pronoun } using:` ,
199+ ` ${ command } ` ,
200+ ] ;
201+
188202 if ( alternatives . length > 0 ) {
189203 lines . push ( "" , "Or:" ) ;
190204 for ( const alt of alternatives ) {
@@ -229,6 +243,10 @@ function buildResolutionMessage(
229243 * user **provided** a value that couldn't be matched, use {@link ResolutionError}
230244 * instead. For malformed input, use {@link ValidationError}.
231245 *
246+ * When `alternatives` is omitted (using defaults), the error assumes auto-detection
247+ * was attempted and produces a "Could not auto-detect ..." headline. When `alternatives`
248+ * is explicitly provided (including `[]`), the error uses "... is/are required." instead.
249+ *
232250 * @param resource - What is required (e.g., "Organization", "Organization and project").
233251 * Use " and " to join compound resources — triggers plural grammar ("are required").
234252 * @param command - **Single-line** CLI usage example (e.g., "sentry org view <org-slug>").
@@ -249,15 +267,26 @@ export class ContextError extends CliError {
249267 constructor (
250268 resource : string ,
251269 command : string ,
252- alternatives : string [ ] = [ ... DEFAULT_CONTEXT_ALTERNATIVES ] ,
270+ alternatives ? : string [ ] ,
253271 note ?: string
254272 ) {
273+ // When alternatives is omitted, auto-detection was tried and failed
274+ const isAutoDetect = alternatives === undefined ;
275+ const resolvedAlternatives = alternatives ?? [
276+ ...DEFAULT_CONTEXT_ALTERNATIVES ,
277+ ] ;
278+
255279 // Include full formatted message so it's shown even when caught by external handlers
256- super ( buildContextMessage ( resource , command , alternatives , note ) ) ;
280+ super (
281+ buildContextMessage ( resource , command , resolvedAlternatives , {
282+ note,
283+ isAutoDetect,
284+ } )
285+ ) ;
257286 this . name = "ContextError" ;
258287 this . resource = resource ;
259288 this . command = command ;
260- this . alternatives = alternatives ;
289+ this . alternatives = resolvedAlternatives ;
261290 this . note = note ;
262291
263292 // Dev-time assertion: command must be a single-line CLI usage example.
0 commit comments