-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ignore exception patterns and namespaces (#892)
* fix: Ignore Exception patterns * Update launch.json
- Loading branch information
Showing
6 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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,9 @@ | ||
export function shouldIgnoreException(name: string, patterns: string[]): boolean { | ||
return patterns.some(pattern => name.match(convertPattern(pattern))) | ||
} | ||
|
||
function convertPattern(pattern: string): string { | ||
const esc = pattern.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d') | ||
const proc = esc.replace(/\\\*\\\*/g, '.*').replace(/\\\*/g, '[^\\\\]*') | ||
return '^' + proc + '$' | ||
} |
This file contains 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 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 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,42 @@ | ||
import { assert } from 'chai' | ||
import { describe, it } from 'mocha' | ||
import { shouldIgnoreException } from '../ignore' | ||
|
||
describe('ignoreExceptions', () => { | ||
it('should match exact', () => { | ||
assert.isTrue(shouldIgnoreException('BaseException', ['BaseException'])) | ||
}) | ||
it('should no match exact', () => { | ||
assert.isFalse(shouldIgnoreException('BaseException', ['SomeOtherException'])) | ||
}) | ||
it('should match wildcard end exact', () => { | ||
assert.isTrue(shouldIgnoreException('BaseException', ['BaseException*'])) | ||
}) | ||
it('should match wildcard end extra', () => { | ||
assert.isTrue(shouldIgnoreException('BaseExceptionMore', ['BaseException*'])) | ||
}) | ||
it('should match namespaced exact', () => { | ||
assert.isTrue(shouldIgnoreException('NS1\\BaseException', ['NS1\\BaseException'])) | ||
}) | ||
it('should match namespaced wildcard exact', () => { | ||
assert.isTrue(shouldIgnoreException('NS1\\BaseException', ['NS1\\BaseException*'])) | ||
}) | ||
it('should match namespaced wildcard extra', () => { | ||
assert.isTrue(shouldIgnoreException('NS1\\BaseExceptionMore', ['NS1\\BaseException*'])) | ||
}) | ||
it('should match namespaced wildcard whole level', () => { | ||
assert.isTrue(shouldIgnoreException('NS1\\BaseException', ['NS1\\*'])) | ||
}) | ||
it('should not match namespaced wildcard more levels', () => { | ||
assert.isFalse(shouldIgnoreException('NS1\\NS2\\BaseException', ['NS1\\*'])) | ||
}) | ||
it('should match namespaced wildcard in middle', () => { | ||
assert.isTrue(shouldIgnoreException('NS1\\NS2\\BaseException', ['NS1\\*\\BaseException'])) | ||
}) | ||
it('should match namespaced wildcard multiple', () => { | ||
assert.isTrue(shouldIgnoreException('NS1\\NS2\\NS3\\BaseException', ['NS1\\*\\*\\BaseException'])) | ||
}) | ||
it('should match namespaced wildcard levels', () => { | ||
assert.isTrue(shouldIgnoreException('NS1\\NS2\\NS3\\BaseException', ['NS1\\**\\BaseException'])) | ||
}) | ||
}) |
This file contains 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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
<?php | ||
|
||
class IgnoreException extends Exception | ||
namespace NS1\NS2; | ||
|
||
class IgnoreException extends \Exception | ||
{} | ||
|
||
try { | ||
// see launch.json ignoreExceptions | ||
throw new IgnoreException('this is an ignored exception'); | ||
} catch (Exception $e) { | ||
} catch (\Exception $e) { | ||
// | ||
} |