File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
packages/cursorless-engine/src/nodeCommon Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ export class TalonSpokenFormsJsonReader implements TalonSpokenForms {
5050 await readFile ( this . cursorlessTalonStateJsonPath , "utf-8" ) ,
5151 ) ;
5252 } catch ( err ) {
53- if ( ( err as any ) ? .code === "ENOENT" ) {
53+ if ( isErrnoException ( err ) && err . code === "ENOENT" ) {
5454 throw new NeedsInitialTalonUpdateError (
5555 `Custom spoken forms file not found at ${ this . cursorlessTalonStateJsonPath } . Using default spoken forms.` ,
5656 ) ;
@@ -73,3 +73,15 @@ export class TalonSpokenFormsJsonReader implements TalonSpokenForms {
7373 this . disposer . dispose ( ) ;
7474 }
7575}
76+
77+ /**
78+ * A user-defined type guard function that checks if a given error is a
79+ * `NodeJS.ErrnoException`.
80+ *
81+ * @param {any } error - The error to check.
82+ * @returns {error is NodeJS.ErrnoException } - Returns `true` if the error is a
83+ * {@link NodeJS.ErrnoException}, otherwise `false`.
84+ */
85+ function isErrnoException ( error : any ) : error is NodeJS . ErrnoException {
86+ return error instanceof Error && "code" in error ;
87+ }
You can’t perform that action at this time.
0 commit comments