-
Notifications
You must be signed in to change notification settings - Fork 10
[Query] Find Exceptions of Functions #2157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
EagleoutIce
merged 8 commits into
main
from
2104-query-to-find-out-what-errors-a-function-may-throw
Jan 3, 2026
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eff28b4
feat: wip: exception checking
EagleoutIce 1c3f8bd
feat: improve error detection in exception handlers!
EagleoutIce 93aef6d
refactor: clean up exception query
EagleoutIce bfa4ac1
doc: document inspect-exceptions query
EagleoutIce 978d1e2
feat: improve handling of finally
EagleoutIce db3c949
refactor: clean up returns in try-catch
EagleoutIce ceabb4a
Merge branch 'main' into 2104-query-to-find-out-what-errors-a-functio…
EagleoutIce dcbf11e
refactor: cleanup
EagleoutIce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id'; | ||
| import type { CallGraph } from '../graph/call-graph'; | ||
| import { VertexType } from '../graph/vertex'; | ||
| import type { ControlDependency } from '../info'; | ||
| import { ExitPointType } from '../info'; | ||
| import type { BuiltInMappingName } from '../environments/built-in'; | ||
| import { isBuiltIn } from '../environments/built-in'; | ||
|
|
||
| const CatchHandlers: ReadonlySet<string> = new Set<BuiltInMappingName>(['builtin:try']); | ||
| export interface ExceptionPoint { | ||
| id: NodeId; | ||
| cds?: readonly ControlDependency[] | undefined; | ||
| } | ||
| /** | ||
| * Collect exception sources of a function in the call graph. | ||
| * This returns the `NodeId`s of functions that may throw exceptions when called by the given function. | ||
| * Please be aware, that these are restricted to functions known by flowR. | ||
| */ | ||
| export function calculateExceptionsOfFunction(id: NodeId, graph: CallGraph): ExceptionPoint[] { | ||
| const collectedExceptions: ExceptionPoint[] = []; | ||
| const visited = new Set<NodeId>(); | ||
| const toVisit: NodeId[] = [id]; | ||
|
|
||
| while(toVisit.length > 0) { | ||
| const currentId = toVisit.pop() as NodeId; | ||
| if(visited.has(currentId)) { | ||
| continue; | ||
| } | ||
| visited.add(currentId); | ||
|
|
||
| const vtx = graph.getVertex(currentId); | ||
| if(!vtx) { | ||
| continue; | ||
| } | ||
|
|
||
| if(isBuiltIn(currentId)) { | ||
| continue; | ||
| } | ||
|
|
||
| if(vtx.tag === VertexType.FunctionDefinition) { | ||
| for(const e of vtx.exitPoints.filter(e => e.type === ExitPointType.Error)) { | ||
| if(!collectedExceptions.find(x => x.id === e.nodeId)) { | ||
| collectedExceptions.push({ id: e.nodeId, cds: e.controlDependencies }); | ||
| } | ||
| } | ||
| } else if(vtx.tag === VertexType.FunctionCall && vtx.origin !== 'unnamed' && vtx.origin.some(c => CatchHandlers.has(c))) { | ||
| // skip the try-catch handlers as they catch all exceptions within their body | ||
| continue; | ||
| } | ||
|
|
||
| const outEdges = graph.outgoingEdges(currentId) ?? []; | ||
| for(const [out] of outEdges) { | ||
| toVisit.push(out); | ||
| } | ||
| } | ||
|
|
||
| return Array.from(collectedExceptions); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.