Skip to content

Commit 92de76d

Browse files
committed
improve error messages
1 parent b846368 commit 92de76d

File tree

8 files changed

+194
-64
lines changed

8 files changed

+194
-64
lines changed

src/vs/workbench/contrib/chat/browser/attachments/promptAttachments/promptAttachmentWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class PromptAttachmentWidget extends Disposable {
118118
// add the issue details in the hover title for the attachment, one
119119
// error/warning at a time because there is a limited space available
120120
if (topError) {
121-
const { isRootError, message: details } = topError;
121+
const { isRootError, localizedMessage: details } = topError;
122122
const isWarning = !isRootError;
123123

124124
this.domNode.classList.add(

src/vs/workbench/contrib/chat/common/promptFileReferenceErrors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { URI } from '../../../../base/common/uri.js';
88
/**
99
* Base prompt parsing error class.
1010
*/
11-
export abstract class ParseError extends Error {
11+
abstract class ParseError extends Error {
1212
/**
1313
* Error type name.
1414
*/

src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/filePromptContentsProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CancellationError } from '../../../../../../base/common/errors.js';
1111
import { PromptContentsProviderBase } from './promptContentsProviderBase.js';
1212
import { VSBufferReadableStream } from '../../../../../../base/common/buffer.js';
1313
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
14-
import { OpenFailed, NotPromptFile, ParseError, FolderReference } from '../../promptFileReferenceErrors.js';
14+
import { OpenFailed, NotPromptFile, ResolveError, FolderReference } from '../../promptFileReferenceErrors.js';
1515
import { FileChangesEvent, FileChangeType, IFileService } from '../../../../../../platform/files/common/files.js';
1616

1717
/**
@@ -81,7 +81,7 @@ export class FilePromptContentProvider extends PromptContentsProviderBase<FileCh
8181

8282
fileStream = await this.fileService.readFileStream(this.uri);
8383
} catch (error) {
84-
if (error instanceof ParseError) {
84+
if (error instanceof ResolveError) {
8585
throw error;
8686
}
8787

src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/promptContentsProviderBase.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import { VSBufferReadableStream } from '../../../../../../base/common/buffer.js'
1212
import { CancellationToken } from '../../../../../../base/common/cancellation.js';
1313
import { isPromptFile } from '../../../../../../platform/prompts/common/constants.js';
1414
import { ObservableDisposable } from '../../../../../../base/common/observableDisposable.js';
15-
import { FailedToResolveContentsStream, ParseError } from '../../promptFileReferenceErrors.js';
15+
import { FailedToResolveContentsStream, ResolveError } from '../../promptFileReferenceErrors.js';
1616
import { cancelPreviousCalls } from '../../../../../../base/common/decorators/cancelPreviousCalls.js';
1717

1818
/**
1919
* Base class for prompt contents providers. Classes that extend this one are responsible to:
2020
*
2121
* - implement the {@linkcode getContentsStream} method to provide the contents stream
22-
* of a prompt; this method should throw a `ParseError` or its derivative if the contents
22+
* of a prompt; this method should throw a `ResolveError` or its derivative if the contents
2323
* cannot be parsed for any reason
2424
* - fire a {@linkcode TChangeEvent} event on the {@linkcode onChangeEmitter} event when
2525
* prompt contents change
@@ -49,7 +49,7 @@ export abstract class PromptContentsProviderBase<
4949

5050
/**
5151
* Function to get contents stream for the provider. This function should
52-
* throw a `ParseError` or its derivative if the contents cannot be parsed.
52+
* throw a `ResolveError` or its derivative if the contents cannot be parsed.
5353
*
5454
* @param changesEvent The event that triggered the change. The special
5555
* `'full'` value means that everything has changed hence entire prompt
@@ -75,12 +75,12 @@ export abstract class PromptContentsProviderBase<
7575
* Event emitter for the prompt contents change event.
7676
* See {@linkcode onContentChanged} for more details.
7777
*/
78-
private readonly onContentChangedEmitter = this._register(new Emitter<VSBufferReadableStream | ParseError>());
78+
private readonly onContentChangedEmitter = this._register(new Emitter<VSBufferReadableStream | ResolveError>());
7979

8080
/**
8181
* Event that fires when the prompt contents change. The event is either
8282
* a `VSBufferReadableStream` stream with changed contents or an instance of
83-
* the `ParseError` class representing a parsing failure case.
83+
* the `ResolveError` class representing a parsing failure case.
8484
*
8585
* `Note!` this field is meant to be used by the external consumers of the prompt
8686
* contents provider that the classes that extend this abstract class.
@@ -112,7 +112,7 @@ export abstract class PromptContentsProviderBase<
112112
this.onContentChangedEmitter.fire(stream);
113113
})
114114
.catch((error) => {
115-
if (error instanceof ParseError) {
115+
if (error instanceof ResolveError) {
116116
this.onContentChangedEmitter.fire(error);
117117

118118
return;

src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptLinkDiagnosticsProvider.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ class PromptLinkDiagnosticsProvider extends ObservableDisposable {
7878
continue;
7979
}
8080

81+
const { originalError } = topError;
82+
8183
// the `NotPromptFile` error is allowed because we allow users
8284
// to include non-prompt file links in the prompt files
8385
// note! this check also handles the `FolderReference` error
84-
if (topError instanceof NotPromptFile) {
86+
if (originalError instanceof NotPromptFile) {
8587
continue;
8688
}
8789

@@ -106,17 +108,19 @@ const toMarker = (
106108
const { topError, linkRange } = link;
107109

108110
// a sanity check because this function must be
109-
// used only if these attributes are present
111+
// used only if these link attributes are present
110112
assertDefined(
111113
topError,
112-
'Error condition must to be defined.',
114+
'Top error must to be defined.',
113115
);
114116
assertDefined(
115117
linkRange,
116118
'Link range must to be defined.',
117119
);
120+
121+
const { originalError } = topError;
118122
assert(
119-
!(topError instanceof NotPromptFile),
123+
!(originalError instanceof NotPromptFile),
120124
'Error must not be of "not prompt file" type.',
121125
);
122126

@@ -127,7 +131,7 @@ const toMarker = (
127131
: MarkerSeverity.Warning;
128132

129133
return {
130-
message: topError.message,
134+
message: topError.localizedMessage,
131135
severity,
132136
...linkRange,
133137
};

0 commit comments

Comments
 (0)