@@ -3,7 +3,7 @@ import * as clack from "@clack/prompts";
3
3
import { readConfig } from "../src/config.js" ;
4
4
import { CliError } from "../src/error.js" ;
5
5
import { enableNpmVersionResolution , enableRemoteModulePreload } from "../src/javascript/imports.js" ;
6
- import { red } from "../src/tty.js" ;
6
+ import { faint , link , red } from "../src/tty.js" ;
7
7
8
8
const args = process . argv . slice ( 2 ) ;
9
9
@@ -26,6 +26,10 @@ const {values, positionals, tokens} = parseArgs({
26
26
help : {
27
27
type : "boolean" ,
28
28
short : "h"
29
+ } ,
30
+ debug : {
31
+ type : "boolean" ,
32
+ short : "d"
29
33
}
30
34
} ,
31
35
strict : false ,
@@ -189,8 +193,36 @@ try {
189
193
}
190
194
}
191
195
process . exit ( error . exitCode ) ;
196
+ } else {
197
+ if ( command && CLACKIFIED_COMMANDS . includes ( command ) ) {
198
+ clack . log . error ( `${ red ( "Error:" ) } ${ error . message } ` ) ;
199
+ if ( values . debug ) {
200
+ clack . outro ( "The full error follows" ) ;
201
+ throw error ;
202
+ } else {
203
+ clack . log . info ( "To see the full stack trace, run with the --debug flag." ) ;
204
+ // clack.outro doesn't handle multiple lines well, so do it manually
205
+ console . log (
206
+ `${ faint ( "│\n│" ) } If you think this is a bug, please file an issue at\n${ faint ( "└" ) } ${ link (
207
+ "https://github.com/observablehq/framework/issues\n"
208
+ ) } `
209
+ ) ;
210
+ }
211
+ } else {
212
+ console . error ( `\n${ red ( "Unexpected error:" ) } ${ error . message } ` ) ;
213
+ if ( values . debug ) {
214
+ console . error ( "The full error follows\n" ) ;
215
+ throw error ;
216
+ } else {
217
+ console . error ( "\nTip: To see the full stack trace, run with the --debug flag.\n" ) ;
218
+ console . error (
219
+ `If you think this is a bug, please file an issue at\n↳ ${ link (
220
+ "https://github.com/observablehq/framework/issues\n"
221
+ ) } `
222
+ ) ;
223
+ }
224
+ }
192
225
}
193
- throw error ;
194
226
}
195
227
196
228
// A wrapper for parseArgs that adds --help functionality with automatic usage.
@@ -199,7 +231,11 @@ try {
199
231
function helpArgs < T extends ParseArgsConfig > ( command : string | undefined , config : T ) : ReturnType < typeof parseArgs < T > > {
200
232
let result : ReturnType < typeof parseArgs < T > > ;
201
233
try {
202
- result = parseArgs < T > ( { ...config , options : { ...config . options , help : { type : "boolean" , short : "h" } } , args} ) ;
234
+ result = parseArgs < T > ( {
235
+ ...config ,
236
+ options : { ...config . options , help : { type : "boolean" , short : "h" } , debug : { type : "boolean" } } ,
237
+ args
238
+ } ) ;
203
239
} catch ( error : any ) {
204
240
if ( ! error . code ?. startsWith ( "ERR_PARSE_ARGS_" ) ) throw error ;
205
241
console . error ( `observable: ${ error . message } . See 'observable help${ command ? ` ${ command } ` : "" } '.` ) ;
0 commit comments