Skip to content

Commit 611968d

Browse files
Remove unnecessary catch which caused confusing error when iteration scopes were missing (#2740)
Today's implementation when you say something like `take every item` will show an error message `Couldn't find containing collectionItem.` even if it's the iteration scope that is missing. This change makes it so that we get the error message `Couldn't find containing iteration scope for collectionItem.` instead. This greatly helps us with diagnosing what actually went wrong. For program languages were a scope is defined in Tree sitter the current error message makes little sense. You could use `take scope` and it works fine, but when you say `take every scope` you get an error message that there is no scope. Much better to actually show that this language is missing an iteration scope. ## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
1 parent 8874c87 commit 611968d

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

packages/cursorless-engine/src/processTargets/modifiers/EveryScopeStage.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,13 @@ export class EveryScopeStage implements ModifierStage {
7373
if (scopes == null) {
7474
// If target had no explicit range, or was contained by a single target
7575
// instance, expand to iteration scope before overlapping
76-
try {
77-
scopes = this.getDefaultIterationRange(
78-
scopeHandler,
79-
this.scopeHandlerFactory,
80-
target,
81-
).flatMap((iterationRange) =>
82-
getScopesOverlappingRange(scopeHandler, editor, iterationRange),
83-
);
84-
} catch (error) {
85-
if (!(error instanceof NoContainingScopeError)) {
86-
throw error;
87-
}
88-
scopes = [];
89-
}
76+
scopes = this.getDefaultIterationRange(
77+
scopeHandler,
78+
this.scopeHandlerFactory,
79+
target,
80+
).flatMap((iterationRange) =>
81+
getScopesOverlappingRange(scopeHandler, editor, iterationRange),
82+
);
9083
}
9184

9285
if (scopes.length === 0) {

0 commit comments

Comments
 (0)