Skip to content

Commit 120f688

Browse files
8ctopuszobo
andauthored
feat: Ignore exceptions based on class name (#882)
* Add possibility to ignore exceptions based on class name * Add ignore exception test * Update readme and comments * Fix test error * Add package.json definition, renamed setting to ignoreExceptions, fix tests. * Changelog. --------- Co-authored-by: Damjan Cvetko <[email protected]>
1 parent 75c3e1d commit 120f688

File tree

7 files changed

+42
-5
lines changed

7 files changed

+42
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.32.0]
8+
9+
- New launch setting ignoreExceptions.
10+
711
## [1.31.1]
812

913
- Fix relative paths and path mappings support.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ More general information on debugging with VS Code can be found on https://code.
7676
- `pathMappings`: A list of server paths mapping to the local source paths on your machine, see "Remote Host Debugging" below
7777
- `log`: Whether to log all communication between VS Code and the adapter to the debug console. See _Troubleshooting_ further down.
7878
- `ignore`: An optional array of glob patterns that errors should be ignored from (for example `**/vendor/**/*.php`)
79+
- `ignoreExceptions`: An optional array of exception class names that should be ignored (for example `BaseException`)
7980
- `skipFiles`: An array of glob patterns, to skip when debugging. Star patterns and negations are allowed, for example, `**/vendor/**` or `!**/vendor/my-module/**`.
8081
- `maxConnections`: Accept only this number of parallel debugging sessions. Additional connections will be dropped and their execution will continue without debugging.
8182
- `proxy`: DBGp Proxy settings

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@
278278
"**/vendor/**"
279279
]
280280
},
281+
"ignoreExceptions": {
282+
"type": "array",
283+
"items": "string",
284+
"description": "An array of exception class names that should be ignored."
285+
},
281286
"log": {
282287
"type": "boolean",
283288
"description": "If true, will log all communication between VS Code and the adapter"

src/phpDebug.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export interface LaunchRequestArguments extends VSCodeDebugProtocol.LaunchReques
7676
log?: boolean
7777
/** Array of glob patterns that errors should be ignored from */
7878
ignore?: string[]
79+
/** Array of glob patterns that exceptions should be ignored from */
80+
ignoreExceptions?: string[]
7981
/** Array of glob patterns that debugger should not step in */
8082
skipFiles?: string[]
8183
/** Xdebug configuration */
@@ -667,15 +669,20 @@ class PhpDebugSession extends vscode.DebugSession {
667669
if (response.exception) {
668670
// If one of the ignore patterns matches, ignore this exception
669671
if (
670-
this._args.ignore &&
671-
this._args.ignore.some(glob =>
672-
minimatch(convertDebuggerPathToClient(response.fileUri).replace(/\\/g, '/'), glob)
673-
)
672+
// ignore files
673+
(this._args.ignore &&
674+
this._args.ignore.some(glob =>
675+
minimatch(convertDebuggerPathToClient(response.fileUri).replace(/\\/g, '/'), glob)
676+
)) ||
677+
// ignore exception class name
678+
(this._args.ignoreExceptions &&
679+
this._args.ignoreExceptions.some(glob => minimatch(response.exception.name, glob)))
674680
) {
675681
const response = await connection.sendRunCommand()
676682
await this._checkStatus(response)
677683
return
678684
}
685+
679686
stoppedEventReason = 'exception'
680687
exceptionText = response.exception.name + ': ' + response.exception.message // this seems to be ignored currently by VS Code
681688
} else if (this._args.stopOnEntry && !this._hasStoppedOnEntry) {

src/test/adapter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ describe('PHP Debug Adapter', () => {
212212
await Promise.all([client.configurationDoneRequest(), client.waitForEvent('terminated')])
213213
})
214214

215+
it('should not break on exception that matches the ignore pattern', async () => {
216+
const program = path.join(TEST_PROJECT, 'ignore_exception.php')
217+
218+
await client.launch({ program, ignoreExceptions: ['IgnoreException'] })
219+
await client.setExceptionBreakpointsRequest({ filters: ['*'] })
220+
await Promise.all([client.configurationDoneRequest(), client.waitForEvent('terminated')])
221+
})
222+
215223
it('should support stopping only on a notice', async () => {
216224
await client.launch({ program })
217225
await client.setExceptionBreakpointsRequest({ filters: ['Notice'] })

testproject/.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"env": {
2222
"XDEBUG_MODE": "debug,develop",
2323
"XDEBUG_CONFIG": "client_port=${port}"
24-
}
24+
},
25+
"ignoreExceptions": ["IgnoreException"]
2526
},
2627
{
2728
//"debugServer": 4711, // Uncomment for debugging the adapter

testproject/ignore_exception.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
class IgnoreException extends Exception
4+
{}
5+
6+
try {
7+
// see launch.json ignoreExceptions
8+
throw new IgnoreException('this is an ignored exception');
9+
} catch (Exception $e) {
10+
//
11+
}

0 commit comments

Comments
 (0)