@@ -17,6 +17,7 @@ import { Emitter, Event } from 'vs/base/common/event';
17
17
import { ExtHostAuthentication } from 'vs/workbench/api/common/extHostAuthentication' ;
18
18
import { localize } from 'vs/nls' ;
19
19
import { INTERNAL_AUTH_PROVIDER_PREFIX } from 'vs/workbench/services/authentication/common/authentication' ;
20
+ import { toErrorMessage } from 'vs/base/common/errorMessage' ;
20
21
21
22
type LanguageModelData = {
22
23
readonly extension : ExtensionIdentifier ;
@@ -54,18 +55,32 @@ class LanguageModelRequest {
54
55
// responses: AsyncIterable<string>[] // FUTURE responses per N
55
56
} ;
56
57
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 ) ;
65
68
}
69
+ } ) . finally ( ( ) => {
70
+ this . _isDone = true ;
66
71
} ) ;
67
72
}
68
73
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
+
69
84
handleFragment ( fragment : IChatResponseFragment ) : void {
70
85
if ( this . _isDone ) {
71
86
return ;
0 commit comments