11/// <reference types="ses"/>
22
3- import { q } from '@endo/errors' ;
4- import { assertChecker , CX } from './passStyle-helpers.js' ;
3+ import { Fail , q } from '@endo/errors' ;
54
6- /** @import {PassStyleHelper} from './internal-types.js' */
7- /** @import {Checker, PassStyle, PassStyleOf} from './types.js' */
5+ /**
6+ * @import {Rejector} from '@endo/errors/rejector.js';
7+ * @import {PassStyleHelper} from './internal-types.js';
8+ * @import {PassStyle} from './types.js';
9+ */
810
911const { getPrototypeOf, getOwnPropertyDescriptors, hasOwn, entries } = Object ;
1012
@@ -50,17 +52,17 @@ harden(getErrorConstructor);
5052
5153/**
5254 * @param {unknown } candidate
53- * @param {Checker } [check]
55+ * @param {Rejector } reject
5456 * @returns {boolean }
5557 */
56- const checkErrorLike = ( candidate , check = undefined ) => {
58+ const confirmErrorLike = ( candidate , reject ) => {
5759 // TODO: Need a better test than instanceof
5860 return (
5961 candidate instanceof Error ||
60- ( ! ! check && CX ( check ) `Error expected: ${ candidate } ` )
62+ ( reject && reject `Error expected: ${ candidate } ` )
6163 ) ;
6264} ;
63- harden ( checkErrorLike ) ;
65+ harden ( confirmErrorLike ) ;
6466/// <reference types="ses"/>
6567
6668/**
@@ -81,34 +83,34 @@ harden(checkErrorLike);
8183 * @param {unknown } candidate
8284 * @returns {boolean }
8385 */
84- export const isErrorLike = candidate => checkErrorLike ( candidate ) ;
86+ export const isErrorLike = candidate => confirmErrorLike ( candidate , false ) ;
8587harden ( isErrorLike ) ;
8688
8789/**
8890 * @param {string } propName
8991 * @param {PropertyDescriptor } desc
9092 * @param {(val: any) => PassStyle } passStyleOfRecur
91- * @param {Checker } [check]
93+ * @param {Rejector } reject
9294 * @returns {boolean }
9395 */
94- export const checkRecursivelyPassableErrorPropertyDesc = (
96+ export const confirmRecursivelyPassableErrorPropertyDesc = (
9597 propName ,
9698 desc ,
9799 passStyleOfRecur ,
98- check = undefined ,
100+ reject ,
99101) => {
100102 if ( desc . enumerable ) {
101103 return (
102- ! ! check &&
103- CX ( check ) `Passable Error ${ q (
104+ reject &&
105+ reject `Passable Error ${ q (
104106 propName ,
105107 ) } own property must not be enumerable: ${ desc } `
106108 ) ;
107109 }
108110 if ( ! hasOwn ( desc , 'value' ) ) {
109111 return (
110- ! ! check &&
111- CX ( check ) `Passable Error ${ q (
112+ reject &&
113+ reject `Passable Error ${ q (
112114 propName ,
113115 ) } own property must be a data property: ${ desc } `
114116 ) ;
@@ -119,95 +121,90 @@ export const checkRecursivelyPassableErrorPropertyDesc = (
119121 case 'stack' : {
120122 return (
121123 typeof value === 'string' ||
122- ( ! ! check &&
123- CX ( check ) `Passable Error ${ q (
124+ ( reject &&
125+ reject `Passable Error ${ q (
124126 propName ,
125127 ) } own property must be a string: ${ value } `)
126128 ) ;
127129 }
128130 case 'cause' : {
129131 // eslint-disable-next-line no-use-before-define
130- return checkRecursivelyPassableError ( value , passStyleOfRecur , check ) ;
132+ return confirmRecursivelyPassableError ( value , passStyleOfRecur , reject ) ;
131133 }
132134 case 'errors' : {
133135 if ( ! Array . isArray ( value ) || passStyleOfRecur ( value ) !== 'copyArray' ) {
134136 return (
135- ! ! check &&
136- CX ( check ) `Passable Error ${ q (
137+ reject &&
138+ reject `Passable Error ${ q (
137139 propName ,
138140 ) } own property must be a copyArray: ${ value } `
139141 ) ;
140142 }
141143 return value . every ( err =>
142144 // eslint-disable-next-line no-use-before-define
143- checkRecursivelyPassableError ( err , passStyleOfRecur , check ) ,
145+ confirmRecursivelyPassableError ( err , passStyleOfRecur , reject ) ,
144146 ) ;
145147 }
146148 default : {
147149 break ;
148150 }
149151 }
150152 return (
151- ! ! check &&
152- CX ( check ) `Passable Error has extra unpassed property ${ q ( propName ) } `
153+ reject && reject `Passable Error has extra unpassed property ${ q ( propName ) } `
153154 ) ;
154155} ;
155- harden ( checkRecursivelyPassableErrorPropertyDesc ) ;
156+ harden ( confirmRecursivelyPassableErrorPropertyDesc ) ;
156157
157158/**
158159 * @param {unknown } candidate
159160 * @param {(val: any) => PassStyle } passStyleOfRecur
160- * @param {Checker } [check]
161+ * @param {Rejector } reject
161162 * @returns {boolean }
162163 */
163- export const checkRecursivelyPassableError = (
164+ export const confirmRecursivelyPassableError = (
164165 candidate ,
165166 passStyleOfRecur ,
166- check = undefined ,
167+ reject ,
167168) => {
168- if ( ! checkErrorLike ( candidate , check ) ) {
169+ if ( ! confirmErrorLike ( candidate , reject ) ) {
169170 return false ;
170171 }
171172 const proto = getPrototypeOf ( candidate ) ;
172173 const { name } = proto ;
173174 const errConstructor = getErrorConstructor ( name ) ;
174175 if ( errConstructor === undefined || errConstructor . prototype !== proto ) {
175176 return (
176- ! ! check &&
177- CX (
178- check ,
179- ) `Passable Error must inherit from an error class .prototype: ${ candidate } `
177+ reject &&
178+ reject `Passable Error must inherit from an error class .prototype: ${ candidate } `
180179 ) ;
181180 }
182181 const descs = getOwnPropertyDescriptors ( candidate ) ;
183182 if ( ! ( 'message' in descs ) ) {
184183 return (
185- ! ! check &&
186- CX (
187- check ,
188- ) `Passable Error must have an own "message" string property: ${ candidate } `
184+ reject &&
185+ reject `Passable Error must have an own "message" string property: ${ candidate } `
189186 ) ;
190187 }
191188
192189 return entries ( descs ) . every ( ( [ propName , desc ] ) =>
193- checkRecursivelyPassableErrorPropertyDesc (
190+ confirmRecursivelyPassableErrorPropertyDesc (
194191 propName ,
195192 desc ,
196193 passStyleOfRecur ,
197- check ,
194+ reject ,
198195 ) ,
199196 ) ;
200197} ;
201- harden ( checkRecursivelyPassableError ) ;
198+ harden ( confirmRecursivelyPassableError ) ;
202199
203200/**
204201 * @type {PassStyleHelper }
205202 */
206203export const ErrorHelper = harden ( {
207204 styleName : 'error' ,
208205
209- canBeValid : checkErrorLike ,
206+ confirmCanBeValid : confirmErrorLike ,
210207
211208 assertRestValid : ( candidate , passStyleOfRecur ) =>
212- checkRecursivelyPassableError ( candidate , passStyleOfRecur , assertChecker ) ,
209+ confirmRecursivelyPassableError ( candidate , passStyleOfRecur , Fail ) ,
213210} ) ;
0 commit comments