@@ -20,6 +20,7 @@ import {
2020import { action as buildActionSource } from "../extension/source/action.ts" ;
2121import { Picker } from "../picker.ts" ;
2222import type { SubmatchContext } from "./submatch.ts" ;
23+ import { ExpectedError , withHandleError } from "../error.ts" ;
2324
2425let zindex = 50 ;
2526
@@ -32,29 +33,36 @@ export const main: Entrypoint = (denops) => {
3233 assert ( options , isOptions ) ;
3334 return startPicker ( denops , args , itemPickerParams , options ) ;
3435 } ,
35- "picker:command" : async ( args ) => {
36+ "picker:command" : withHandleError ( denops , async ( args ) => {
3637 await loadUserConfig ( denops ) ;
3738 // Split the command arguments
3839 const [ name , ...sourceArgs ] = ensure ( args , isStringArray ) ;
3940 // Load user config
4041 const itemPickerParams = getItemPickerParams ( name ) ;
4142 if ( ! itemPickerParams ) {
42- throw new Error ( `Config for picker "${ name } " is not found` ) ;
43+ throw new ExpectedError (
44+ `No item picker "${ name } " is found. Available item pickers are: ${
45+ listItemPickerNames ( ) . join ( ", " )
46+ } `,
47+ ) ;
4348 }
4449 await startPicker (
4550 denops ,
4651 sourceArgs ,
4752 itemPickerParams ,
4853 { signal : denops . interrupted } ,
4954 ) ;
50- } ,
51- "picker:command:complete" : async ( arglead , cmdline , cursorpos ) => {
52- await loadUserConfig ( denops ) ;
53- assert ( arglead , is . String ) ;
54- assert ( cmdline , is . String ) ;
55- assert ( cursorpos , is . Number ) ;
56- return listItemPickerNames ( ) . filter ( ( name ) => name . startsWith ( arglead ) ) ;
57- } ,
55+ } ) ,
56+ "picker:command:complete" : withHandleError (
57+ denops ,
58+ async ( arglead , cmdline , cursorpos ) => {
59+ await loadUserConfig ( denops ) ;
60+ assert ( arglead , is . String ) ;
61+ assert ( cmdline , is . String ) ;
62+ assert ( cursorpos , is . Number ) ;
63+ return listItemPickerNames ( ) . filter ( ( name ) => name . startsWith ( arglead ) ) ;
64+ } ,
65+ ) ,
5866 // TODO: Remove this API prior to release v1.0.0
5967 // DEPRECATED: Use "submatch:start" instead
6068 "picker:start" : async ( _args , _screen , params , options ) => {
@@ -155,7 +163,13 @@ async function startPicker(
155163 // Execute the action
156164 const action = itemPickerParams . actions [ actionName ] ;
157165 if ( ! action ) {
158- throw new Error ( `Action "${ actionName } " is not found` ) ;
166+ throw new ExpectedError (
167+ `No action "${ actionName } " is found. Available actions are: ${
168+ Object . keys ( itemPickerParams . actions ) . join (
169+ ", " ,
170+ )
171+ } `,
172+ ) ;
159173 }
160174 const actionParams = {
161175 // TODO: Drop the following attributes prior to release v1.0.0
0 commit comments