1
0
mirror of synced 2024-12-04 19:17:56 +01:00

more debugging

This commit is contained in:
d98762625 2019-03-11 09:47:58 +00:00
parent e4b688a2c3
commit 14d591caa1
4 changed files with 24 additions and 4 deletions

View File

@ -44,6 +44,10 @@ class Dish {
if (dishOrInput && if (dishOrInput &&
dishOrInput.hasOwnProperty("value") && dishOrInput.hasOwnProperty("value") &&
dishOrInput.hasOwnProperty("type")) { dishOrInput.hasOwnProperty("type")) {
console.log('first setting');
console.log(dishOrInput);
console.log(dishOrInput.constructor.name);
console.log(dishOrInput.value);
this.set(dishOrInput.value, dishOrInput.type); this.set(dishOrInput.value, dishOrInput.type);
// input and type defined separately // input and type defined separately
} else if (dishOrInput && type) { } else if (dishOrInput && type) {
@ -99,6 +103,8 @@ class Dish {
* @returns {string} The data type as a string. * @returns {string} The data type as a string.
*/ */
static enumLookup(typeEnum) { static enumLookup(typeEnum) {
console.trace('enumLookup');
console.log('type ' + typeEnum);
switch (typeEnum) { switch (typeEnum) {
case Dish.BYTE_ARRAY: case Dish.BYTE_ARRAY:
return "byteArray"; return "byteArray";
@ -174,11 +180,16 @@ class Dish {
type = Dish.typeEnum(type); type = Dish.typeEnum(type);
} }
console.log('Dish setting:');
console.log(value);
console.log(type);
log.debug("Dish type: " + Dish.enumLookup(type)); log.debug("Dish type: " + Dish.enumLookup(type));
this.value = value; this.value = value;
this.type = type; this.type = type;
if (!this.valid()) { if (!this.valid()) {
console.log('invalid!');
const sample = Utils.truncate(JSON.stringify(this.value), 13); const sample = Utils.truncate(JSON.stringify(this.value), 13);
throw new DishError(`Data is not a valid ${Dish.enumLookup(type)}: ${sample}`); throw new DishError(`Data is not a valid ${Dish.enumLookup(type)}: ${sample}`);
} }
@ -220,6 +231,8 @@ class Dish {
// All values can be serialised in some manner, so we return true in all cases // All values can be serialised in some manner, so we return true in all cases
return true; return true;
case Dish.FILE: case Dish.FILE:
console.log("Validating on file");
console.log(this.value instanceof File);
return this.value instanceof File; return this.value instanceof File;
case Dish.LIST_FILE: case Dish.LIST_FILE:
return this.value instanceof Array && return this.value instanceof Array &&
@ -336,6 +349,8 @@ class Dish {
// Node environment => translate is sync // Node environment => translate is sync
if (Utils.isNode()) { if (Utils.isNode()) {
console.log('_translate toType:');
console.log(toType);
this._toByteArray(); this._toByteArray();
this._fromByteArray(toType, notUTF8); this._fromByteArray(toType, notUTF8);
@ -389,6 +404,7 @@ class Dish {
}; };
try { try {
console.log("_tyByteArray this.type: " + this.type);
return toByteArrayFuncs[Utils.isNode() && "node" || "browser"][this.type](); return toByteArrayFuncs[Utils.isNode() && "node" || "browser"][this.type]();
} catch (err) { } catch (err) {
throw new DishError(`Error translating from ${Dish.enumLookup(this.type)} to byteArray: ${err}`); throw new DishError(`Error translating from ${Dish.enumLookup(this.type)} to byteArray: ${err}`);

View File

@ -967,7 +967,7 @@ class Utils {
throw new TypeError("Browser environment cannot support readFileSync"); throw new TypeError("Browser environment cannot support readFileSync");
} }
return Buffer.from(file).buffer; return Buffer.from(file.data).buffer;
} }

View File

@ -19,6 +19,8 @@ class DishFile extends DishTranslationType {
static toByteArray() { static toByteArray() {
DishFile.checkForValue(this.value); DishFile.checkForValue(this.value);
if (Utils.isNode()) { if (Utils.isNode()) {
console.log("valie: ");
console.log(this.value);
this.value = Array.prototype.slice.call(Utils.readFileSync(this.value)); this.value = Array.prototype.slice.call(Utils.readFileSync(this.value));
} else { } else {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View File

@ -140,7 +140,7 @@ function prepareOp(opInstance, input, args) {
function createArgOptions(op) { function createArgOptions(op) {
const result = {}; const result = {};
op.args.forEach((a) => { op.args.forEach((a) => {
if (a.type === "option") { if (a.type === "option" || a.type === "editableOption") {
result[sentenceToCamelCase(a.name)] = removeSubheadingsFromArray(a.value); result[sentenceToCamelCase(a.name)] = removeSubheadingsFromArray(a.value);
} else if (a.type === "toggleString") { } else if (a.type === "toggleString") {
result[sentenceToCamelCase(a.name)] = removeSubheadingsFromArray(a.toggleValues); result[sentenceToCamelCase(a.name)] = removeSubheadingsFromArray(a.toggleValues);
@ -183,7 +183,7 @@ export function wrap(OpClass) {
const result = await opInstance.run(transformedInput, transformedArgs); const result = await opInstance.run(transformedInput, transformedArgs);
return new NodeDish({ return new NodeDish({
value: result, value: result,
type: opInstance.outputType type: opInstance.outputType,
}); });
}; };
} else { } else {
@ -197,9 +197,11 @@ export function wrap(OpClass) {
wrapped = (input, args=null) => { wrapped = (input, args=null) => {
const {transformedInput, transformedArgs} = prepareOp(opInstance, input, args); const {transformedInput, transformedArgs} = prepareOp(opInstance, input, args);
const result = opInstance.run(transformedInput, transformedArgs); const result = opInstance.run(transformedInput, transformedArgs);
console.log('Result:');
console.log(result);
return new NodeDish({ return new NodeDish({
value: result, value: result,
type: opInstance.outputType type: opInstance.outputType,
}); });
}; };
} }