mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-05-10 16:37:12 +00:00
Improve error message
This commit is contained in:
parent
711fbe1f1a
commit
c42beaa4b0
@ -43,11 +43,11 @@ export class SchemaValidationError extends Error {
|
|||||||
? "array"
|
? "array"
|
||||||
: typeof provided;
|
: typeof provided;
|
||||||
|
|
||||||
const message = `Type mismatch. Path: ${path.join(
|
const message = `Aqua and schema type mismatch. Path: ${path.join(
|
||||||
".",
|
".",
|
||||||
)}; Expected: ${expected}; Given: ${given};\n\nschema: ${JSON.stringify(
|
)}; Expected: ${expected}; Given: ${given};\n\nschema: ${JSON.stringify(
|
||||||
schema,
|
schema,
|
||||||
)}`;
|
)}; Try to recompile rust services and aqua and make sure that you are using up-to-date versions of aqua libraries`;
|
||||||
|
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ export function aqua2js(
|
|||||||
return null;
|
return null;
|
||||||
} else if (schema.tag === "option") {
|
} else if (schema.tag === "option") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Value and schema doesn't match");
|
throw new SchemaValidationError([], schema, "array", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.length === 0) {
|
if (value.length === 0) {
|
||||||
@ -118,7 +118,7 @@ export function aqua2js(
|
|||||||
return value;
|
return value;
|
||||||
} else if (schema.tag === "array") {
|
} else if (schema.tag === "array") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Value and schema doesn't match");
|
throw new SchemaValidationError([], schema, "array", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return value.map((y) => {
|
return value.map((y) => {
|
||||||
@ -126,7 +126,7 @@ export function aqua2js(
|
|||||||
});
|
});
|
||||||
} else if (schema.tag === "unlabeledProduct") {
|
} else if (schema.tag === "unlabeledProduct") {
|
||||||
if (!Array.isArray(value)) {
|
if (!Array.isArray(value)) {
|
||||||
throw new Error("Value and schema doesn't match");
|
throw new SchemaValidationError([], schema, "array", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return value.map((y, i) => {
|
return value.map((y, i) => {
|
||||||
@ -134,7 +134,7 @@ export function aqua2js(
|
|||||||
});
|
});
|
||||||
} else if (["labeledProduct", "struct"].includes(schema.tag)) {
|
} else if (["labeledProduct", "struct"].includes(schema.tag)) {
|
||||||
if (typeof value !== "object" || value == null || Array.isArray(value)) {
|
if (typeof value !== "object" || value == null || Array.isArray(value)) {
|
||||||
throw new Error("Value and schema doesn't match");
|
throw new SchemaValidationError([], schema, "object", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
@ -144,7 +144,7 @@ export function aqua2js(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Unexpected tag: " + JSON.stringify(schema));
|
throw new SchemaValidationError([], schema, "never", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user