Skip to content
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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

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 than a? As written noop should not be used here because it does not return its first argument.

Copy link
Member Author

@Avaq Avaq Jul 4, 2018

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 return undefined.


// compose :: (b -> c, a -> b) -> (a -> c)
function compose(f, g) {
return function(x) {
Expand Down Expand Up @@ -281,6 +284,9 @@
};
}

// noop :: () -> Undefined
function noop() {}

// or :: (Array a, Array a) -> Array a
function or(xs, ys) { return isEmpty (xs) ? ys : xs; }

Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The 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,
Expand All @@ -2081,6 +2087,8 @@
' but received ' + numArgs (args.length) +
toMarkdownList ('.\n', ':\n\n', show, args)
));
captureStackTrace (e, fn);
return e;
}

// constraintsRepr :: ... -> String
Expand Down Expand Up @@ -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' +
Expand All @@ -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 !
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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 (
Expand Down