MCPcopy Create free account
hub / github.com/agentrpc/agentrpc / ajvErrorToFailures

Function ajvErrorToFailures

sdk-node/src/util.ts:150–181  ·  view source on GitHub ↗
(
  error: Error,
)

Source from the content-addressed store, hash-verified

148 * Accepts an AJV compilation error and extracts the error details from the message.
149 */
150export const ajvErrorToFailures = (
151 error: Error,
152): { path: string; error: string }[] => {
153 // example: /data/properties/name some error message
154 if (error.message.startsWith("schema is invalid:")) {
155 return error.message
156 .replace("schema is invalid:", "")
157 .split(",")
158 .map((s) => s.trim())
159 .map((s) => {
160 const firstSpace = s.indexOf(" ");
161
162 if (firstSpace === -1) {
163 throw new AgentRPCError("Could not extract failures from AJV error", {
164 error,
165 });
166 }
167
168 return {
169 path: s.slice(0, firstSpace),
170 error: s.slice(firstSpace + 1),
171 };
172 });
173 }
174
175 return [
176 {
177 path: "",
178 error: error.message,
179 },
180 ];
181};
182
183// eslint-disable-next-line @typescript-eslint/no-explicit-any
184export const isZodType = (input: any): input is z.ZodTypeAny => {

Callers 2

util.test.tsFile · 0.90
validateFunctionSchemaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected