mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 19:38:58 +00:00
enhance INVALID_ARG_TYPE and cleanup some node:buffer error handling (#14200)
This commit is contained in:
@@ -307,45 +307,43 @@ WTF::String ERR_OUT_OF_RANGE(JSC::ThrowScope& scope, JSC::JSGlobalObject* global
|
||||
|
||||
namespace ERR {
|
||||
|
||||
JSC::EncodedJSValue INVALID_ARG_TYPE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, ASCIILiteral val_arg_name, ASCIILiteral val_expected_type, JSC::JSValue val_actual_value, bool instance)
|
||||
JSC::EncodedJSValue INVALID_ARG_TYPE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, ASCIILiteral val_arg_name, ASCIILiteral val_expected_type, JSC::JSValue val_actual_value)
|
||||
{
|
||||
auto arg_name = val_arg_name.span8();
|
||||
ASSERT(WTF::charactersAreAllASCII(arg_name));
|
||||
|
||||
auto arg_kind = String(arg_name).startsWith("options."_s) ? "property"_s : "argument"_s;
|
||||
|
||||
auto expected_type = val_expected_type.span8();
|
||||
ASSERT(WTF::charactersAreAllASCII(expected_type));
|
||||
|
||||
auto ty_first_char = expected_type[0];
|
||||
auto ty_kind = ty_first_char >= 'A' && ty_first_char <= 'Z' ? "an instance of"_s : "of type"_s;
|
||||
|
||||
auto actual_value = JSValueToStringSafe(globalObject, val_actual_value);
|
||||
RETURN_IF_EXCEPTION(throwScope, {});
|
||||
|
||||
if (instance) {
|
||||
auto message = makeString("The \""_s, arg_name, "\" argument must be an instance of "_s, expected_type, ". Received "_s, actual_value);
|
||||
throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_INVALID_ARG_TYPE, message));
|
||||
return {};
|
||||
}
|
||||
|
||||
auto message = makeString("The \""_s, arg_name, "\" argument must be of type "_s, expected_type, ". Received "_s, actual_value);
|
||||
auto message = makeString("The \""_s, arg_name, "\" "_s, arg_kind, " must be "_s, ty_kind, " "_s, expected_type, ". Received "_s, actual_value);
|
||||
throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_INVALID_ARG_TYPE, message));
|
||||
return {};
|
||||
}
|
||||
JSC::EncodedJSValue INVALID_ARG_TYPE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, JSC::JSValue val_arg_name, ASCIILiteral val_expected_type, JSC::JSValue val_actual_value, bool instance)
|
||||
JSC::EncodedJSValue INVALID_ARG_TYPE(JSC::ThrowScope& throwScope, JSC::JSGlobalObject* globalObject, JSC::JSValue val_arg_name, ASCIILiteral val_expected_type, JSC::JSValue val_actual_value)
|
||||
{
|
||||
auto arg_name = val_arg_name.toWTFString(globalObject);
|
||||
RETURN_IF_EXCEPTION(throwScope, {});
|
||||
|
||||
auto arg_kind = String(arg_name).startsWith("options."_s) ? "property"_s : "argument"_s;
|
||||
|
||||
auto expected_type = val_expected_type.span8();
|
||||
ASSERT(WTF::charactersAreAllASCII(expected_type));
|
||||
|
||||
auto ty_first_char = expected_type[0];
|
||||
auto ty_kind = ty_first_char >= 'A' && ty_first_char <= 'Z' ? "an instance of"_s : "of type"_s;
|
||||
|
||||
auto actual_value = JSValueToStringSafe(globalObject, val_actual_value);
|
||||
RETURN_IF_EXCEPTION(throwScope, {});
|
||||
|
||||
if (instance) {
|
||||
auto message = makeString("The \""_s, arg_name, "\" argument must be an instance of "_s, expected_type, ". Received "_s, actual_value);
|
||||
throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_INVALID_ARG_TYPE, message));
|
||||
return {};
|
||||
}
|
||||
|
||||
auto message = makeString("The \""_s, arg_name, "\" argument must be of type "_s, expected_type, ". Received "_s, actual_value);
|
||||
auto message = makeString("The \""_s, arg_name, "\" "_s, arg_kind, " must be "_s, ty_kind, " "_s, expected_type, ". Received "_s, actual_value);
|
||||
throwScope.throwException(globalObject, createError(globalObject, ErrorCode::ERR_INVALID_ARG_TYPE, message));
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user