@@ -17,6 +17,7 @@ import { Emitter, Event } from 'vs/base/common/event';
1717import { ExtHostAuthentication } from 'vs/workbench/api/common/extHostAuthentication' ;
1818import { localize } from 'vs/nls' ;
1919import { INTERNAL_AUTH_PROVIDER_PREFIX } from 'vs/workbench/services/authentication/common/authentication' ;
20+ import { toErrorMessage } from 'vs/base/common/errorMessage' ;
2021
2122type LanguageModelData = {
2223 readonly extension : ExtensionIdentifier ;
@@ -54,18 +55,32 @@ class LanguageModelRequest {
5455 // responses: AsyncIterable<string>[] // FUTURE responses per N
5556 } ;
5657
57- promise . finally ( ( ) => {
58- this . _isDone = true ;
59- if ( this . _responseStreams . size > 0 ) {
60- for ( const [ , value ] of this . _responseStreams ) {
61- value . stream . resolve ( ) ;
62- }
63- } else {
64- this . _defaultStream . resolve ( ) ;
58+ promise . then ( ( ) => {
59+ for ( const stream of this . _streams ( ) ) {
60+ stream . resolve ( ) ;
61+ }
62+ } ) . catch ( err => {
63+ if ( ! ( err instanceof Error ) ) {
64+ err = new Error ( toErrorMessage ( err ) , { cause : err } ) ;
65+ }
66+ for ( const stream of this . _streams ( ) ) {
67+ stream . reject ( err ) ;
6568 }
69+ } ) . finally ( ( ) => {
70+ this . _isDone = true ;
6671 } ) ;
6772 }
6873
74+ private * _streams ( ) {
75+ if ( this . _responseStreams . size > 0 ) {
76+ for ( const [ , value ] of this . _responseStreams ) {
77+ yield value . stream ;
78+ }
79+ } else {
80+ yield this . _defaultStream ;
81+ }
82+ }
83+
6984 handleFragment ( fragment : IChatResponseFragment ) : void {
7085 if ( this . _isDone ) {
7186 return ;
0 commit comments