-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
WIP: Exclude internal stack frames from littering error messages #213
Open
Avaq
wants to merge
1
commit into
main
Choose a base branch
from
avaq/stacktraces
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -239,6 +239,9 @@ | |
// always2 :: a -> (b, c) -> a | ||
function always2(x) { return function(y, z) { return x; }; } | ||
|
||
// captureStackTrace :: Assignable a => (a, Function) -> a | ||
var captureStackTrace = Error.captureStackTrace || noop; | ||
|
||
// compose :: (b -> c, a -> b) -> (a -> c) | ||
function compose(f, g) { | ||
return function(x) { | ||
|
@@ -281,6 +284,9 @@ | |
}; | ||
} | ||
|
||
// noop :: () -> Undefined | ||
function noop() {} | ||
|
||
// or :: (Array a, Array a) -> Array a | ||
function or(xs, ys) { return isEmpty (xs) ? ys : xs; } | ||
|
||
|
@@ -2061,12 +2067,12 @@ | |
//. Multiple constraints may be placed on a type variable by including | ||
//. multiple `TypeClass` values in the array (e.g. `{a: [Foo, Bar, Baz]}`). | ||
|
||
// invalidArgumentsCount :: (TypeInfo, Integer, Integer, Array Any) -> Error | ||
// invalidArgumentsCount :: (TypeInfo, Integer, Integer, Array Any, Function) -> Error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: This line is too long now. Argument types should be moved into the argument list as is done with other functions. |
||
// | ||
// This function is used in `curry` when a function defined via `def` | ||
// is applied to too many arguments. | ||
function invalidArgumentsCount(typeInfo, index, numArgsExpected, args) { | ||
return new TypeError (trimTrailingSpaces ( | ||
function invalidArgumentsCount(typeInfo, index, numArgsExpected, args, fn) { | ||
var e = new TypeError (trimTrailingSpaces ( | ||
q (typeInfo.name) + ' applied to the wrong number of arguments\n\n' + | ||
underline ( | ||
typeInfo, | ||
|
@@ -2081,6 +2087,8 @@ | |
' but received ' + numArgs (args.length) + | ||
toMarkdownList ('.\n', ':\n\n', show, args) | ||
)); | ||
captureStackTrace (e, fn); | ||
return e; | ||
} | ||
|
||
// constraintsRepr :: ... -> String | ||
|
@@ -2387,9 +2395,10 @@ | |
typeInfo, // :: TypeInfo | ||
index, // :: Integer | ||
numArgsExpected, // :: Integer | ||
args // :: Array Any | ||
args, // :: Array Any | ||
fn // :: Function | ||
) { | ||
return new TypeError (trimTrailingSpaces ( | ||
var e = new TypeError (trimTrailingSpaces ( | ||
q (typeInfo.name) + | ||
' applied ' + showTypeQuoted (typeInfo.types[index]) + | ||
' to the wrong number of arguments\n\n' + | ||
|
@@ -2414,6 +2423,8 @@ | |
' but received ' + numArgs (args.length) + | ||
toMarkdownList ('.\n', ':\n\n', show, args) | ||
)); | ||
captureStackTrace (e, fn); | ||
return e; | ||
} | ||
|
||
// assertRight :: Either (() -> Error) a -> a ! | ||
|
@@ -2480,12 +2491,13 @@ | |
var isThunk = expType.types.$1.type.type === NO_ARGUMENTS; | ||
var numArgsExpected = isThunk ? 0 : expType.keys.length - 1; | ||
var typeVarMap = _typeVarMap; | ||
return function(x) { | ||
return function sanctuaryWrappedFunction(x) { | ||
if (arguments.length !== numArgsExpected) { | ||
throw invalidArgumentsLength (typeInfo, | ||
index, | ||
numArgsExpected, | ||
slice.call (arguments)); | ||
slice.call (arguments), | ||
sanctuaryWrappedFunction); | ||
} | ||
|
||
var args = arguments; | ||
|
@@ -2507,10 +2519,14 @@ | |
|
||
// wrapNext :: (TypeVarMap, Array Any, Integer) -> (a -> b) | ||
function wrapNext(_typeVarMap, _values, index) { | ||
return function(x) { | ||
return function sanctuaryWrappedFunction(x) { | ||
var args = slice.call (arguments); | ||
if (args.length !== 1) { | ||
throw invalidArgumentsCount (typeInfo, index, 1, args); | ||
throw invalidArgumentsCount (typeInfo, | ||
index, | ||
1, | ||
args, | ||
sanctuaryWrappedFunction); | ||
} | ||
var typeVarMap = (assertRight ( | ||
satisfactoryTypes (env, | ||
|
@@ -2544,9 +2560,13 @@ | |
} | ||
|
||
var wrapped = typeInfo.types[0].type === NO_ARGUMENTS ? | ||
function() { | ||
function sanctuaryWrappedFunction() { | ||
if (arguments.length !== 0) { | ||
throw invalidArgumentsCount (typeInfo, 0, 0, slice.call (arguments)); | ||
throw invalidArgumentsCount (typeInfo, | ||
0, | ||
0, | ||
slice.call (arguments), | ||
sanctuaryWrappedFunction); | ||
} | ||
var value = impl (); | ||
var typeVarMap = assertRight ( | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the return type be
Undefined
rather thana
? As writtennoop
should not be used here because it does not return its first argument.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right.
Error.captureStackTrace
does actually returnundefined
.