@@ -2222,6 +2222,65 @@ func TestDoCmdFunctionInvokeWithUnknownInputFormat(t *testing.T) {
22222222 assert .ErrorContains (t , err , "converter not found" )
22232223}
22242224
2225+ // TestDoCmdFunctionInvokeWithConverterMissingConvertSnippet verifies that a converter plugin that exists but does not
2226+ // implement ConvertSnippet produces a targeted error instead of leaking the raw RPC error.
2227+ func TestDoCmdFunctionInvokeWithConverterMissingConvertSnippet (t * testing.T ) {
2228+ t .Parallel ()
2229+
2230+ mlm := & cmdBackend.MockLoginManager {}
2231+ mws := & pkgWorkspace.MockContext {}
2232+ host := func () (plugin.Host , error ) {
2233+ return & plugin.MockHost {LoaderAddrF : func () string { return "loader-address" }}, nil
2234+ }
2235+ loadConverter := func (
2236+ _ * plugin.Context , name string , _ func (sev diag.Severity , msg string ),
2237+ ) (plugin.Converter , error ) {
2238+ assert .Equal (t , "yaml" , name )
2239+ return & plugin.MockConverter {}, nil
2240+ }
2241+ loader := func (ctx context.Context , pctx * plugin.Context , wd , source string ) (plugin.Provider , error ) {
2242+ spec := schema.PackageSpec {
2243+ Name : "azure" ,
2244+ Functions : map [string ]schema.FunctionSpec {
2245+ "azure:index:myFunction" : {
2246+ Inputs : & schema.ObjectTypeSpec {
2247+ Properties : map [string ]schema.PropertySpec {
2248+ "x" : {TypeSpec : schema.TypeSpec {Type : "string" }},
2249+ },
2250+ },
2251+ Outputs : & schema.ObjectTypeSpec {
2252+ Properties : map [string ]schema.PropertySpec {
2253+ "y" : {TypeSpec : schema.TypeSpec {Type : "string" }},
2254+ },
2255+ },
2256+ },
2257+ },
2258+ }
2259+ return & testProvider {
2260+ spec : spec ,
2261+ MockProvider : plugin.MockProvider {
2262+ InvokeF : func (ctx context.Context , req plugin.InvokeRequest ) (plugin.InvokeResponse , error ) {
2263+ require .Fail (t , "Invoke should not be called when the converter cannot convert snippets" )
2264+ return plugin.InvokeResponse {}, nil
2265+ },
2266+ },
2267+ }, nil
2268+ }
2269+
2270+ inputFile := writeHCLFile (t , "inputs.yaml" , "x: hello" )
2271+
2272+ var stdout bytes.Buffer
2273+ cmd := NewDoCmd (mlm , mws , loader , host , loadConverter )
2274+ cmd .SetOut (& stdout )
2275+ cmd .SetErr (& stdout )
2276+ cmd .SetArgs ([]string {"azure:myFunction" , "--input" , "yaml" , "--input-file" , inputFile })
2277+ err := cmd .Execute ()
2278+ require .Error (t , err )
2279+ assert .ErrorContains (t , err , "yaml input converter does not support snippet conversion; " +
2280+ "use pcl format or try installing a newer yaml converter" )
2281+ assert .NotContains (t , err .Error (), "ConvertSnippet not implemented" )
2282+ }
2283+
22252284// TestDoCmdFunctionInvokeWithConverterDiagnostics asserts that diagnostic-level errors from ConvertSnippet are
22262285// surfaced and that Invoke is never called.
22272286func TestDoCmdFunctionInvokeWithConverterDiagnostics (t * testing.T ) {
0 commit comments