Added automated parsing of subvalues in JSON to make even more values into proper usable keys
This commit is contained in:
@@ -3070,12 +3070,14 @@ class AppBase:
|
|||||||
|
|
||||||
#newres = ""
|
#newres = ""
|
||||||
iteration_count = 0
|
iteration_count = 0
|
||||||
|
found_error = ""
|
||||||
while True:
|
while True:
|
||||||
iteration_count += 1
|
iteration_count += 1
|
||||||
if iteration_count > 10:
|
if iteration_count > 10:
|
||||||
newres = {
|
newres = {
|
||||||
"success": False,
|
"success": False,
|
||||||
"reason": "Iteration count more than 10. This happens if the input to the action is wrong. Try remaking the action, and contact support@shuffler.io if this persists.",
|
"reason": "Iteration count more than 10. This happens if the input to the action is wrong. Try remaking the action, and contact support@shuffler.io if this persists.",
|
||||||
|
"details": found_error,
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -3085,14 +3087,25 @@ class AppBase:
|
|||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
newres = ""
|
newres = ""
|
||||||
self.logger.info(f"[DEBUG] Got exec error: {e}")
|
self.logger.info(f"[DEBUG] Got exec error: {e}")
|
||||||
|
try:
|
||||||
|
e = json.loads(f"{e}")
|
||||||
|
except:
|
||||||
|
e = f"{e}"
|
||||||
|
|
||||||
|
found_error = e
|
||||||
errorstring = f"{e}"
|
errorstring = f"{e}"
|
||||||
|
|
||||||
if "the JSON object must be" in errorstring:
|
if "the JSON object must be" in errorstring:
|
||||||
self.logger.info("[ERROR] Something is wrong with the input for this function. Are lists and JSON data handled parsed properly?")
|
self.logger.info("[ERROR] Something is wrong with the input for this function. Are lists and JSON data handled parsed properly?")
|
||||||
|
try:
|
||||||
|
e = json.loads(f"{e}")
|
||||||
|
except:
|
||||||
|
e = f"{e}"
|
||||||
|
|
||||||
raise Exception(json.dumps({
|
raise Exception(json.dumps({
|
||||||
"success": False,
|
"success": False,
|
||||||
"reason": "An exception occurred while running this function. See exception for more details and contact support if this persists (support@shuffler.io)",
|
"reason": "An exception occurred while running this function. See exception for more details and contact support if this persists (support@shuffler.io)",
|
||||||
"exception": f"{e}",
|
"exception": e,
|
||||||
}))
|
}))
|
||||||
elif "got an unexpected keyword argument" in errorstring:
|
elif "got an unexpected keyword argument" in errorstring:
|
||||||
fieldsplit = errorstring.split("'")
|
fieldsplit = errorstring.split("'")
|
||||||
@@ -3112,10 +3125,16 @@ class AppBase:
|
|||||||
})
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.info("[ERROR] Something is wrong with the input for this function. Are lists and JSON data handled parsed properly?")
|
self.logger.info("[ERROR] Something is wrong with the input for this function. Are lists and JSON data handled parsed properly?")
|
||||||
|
|
||||||
|
try:
|
||||||
|
e = json.loads(f"{e}")
|
||||||
|
except:
|
||||||
|
e = f"{e}"
|
||||||
|
|
||||||
raise Exception(json.dumps({
|
raise Exception(json.dumps({
|
||||||
"success": False,
|
"success": False,
|
||||||
"reason": "An exception occurred while running this function. See exception for more details and contact support if this persists (support@shuffler.io)",
|
"reason": "An exception occurred while running this function. See exception for more details and contact support if this persists (support@shuffler.io)",
|
||||||
"exception": f"{e}",
|
"exception": e,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
# Forcing async wait in case of old apps that use async (backwards compatibility)
|
# Forcing async wait in case of old apps that use async (backwards compatibility)
|
||||||
@@ -3255,6 +3274,11 @@ class AppBase:
|
|||||||
self.logger.info(f"[ERROR] Failed to execute request (requests): {e}")
|
self.logger.info(f"[ERROR] Failed to execute request (requests): {e}")
|
||||||
self.logger.exception(f"[ERROR] Failed to execute {e}-{action['id']}")
|
self.logger.exception(f"[ERROR] Failed to execute {e}-{action['id']}")
|
||||||
self.action_result["status"] = "SUCCESS"
|
self.action_result["status"] = "SUCCESS"
|
||||||
|
try:
|
||||||
|
e = json.loads(f"{e}")
|
||||||
|
except:
|
||||||
|
e = f"{e}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.action_result["result"] = json.dumps({
|
self.action_result["result"] = json.dumps({
|
||||||
"success": False,
|
"success": False,
|
||||||
@@ -3268,9 +3292,14 @@ class AppBase:
|
|||||||
self.logger.info(f"[ERROR] Failed to execute: {e}")
|
self.logger.info(f"[ERROR] Failed to execute: {e}")
|
||||||
self.logger.exception(f"[ERROR] Failed to execute {e}-{action['id']}")
|
self.logger.exception(f"[ERROR] Failed to execute {e}-{action['id']}")
|
||||||
self.action_result["status"] = "FAILURE"
|
self.action_result["status"] = "FAILURE"
|
||||||
|
try:
|
||||||
|
e = json.loads(f"{e}")
|
||||||
|
except:
|
||||||
|
e = f"{e}"
|
||||||
|
|
||||||
self.action_result["result"] = json.dumps({
|
self.action_result["result"] = json.dumps({
|
||||||
"success": False,
|
"success": False,
|
||||||
"reason": f"General exception.",
|
"reason": f"General exception",
|
||||||
"details": e,
|
"details": e,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -12021,11 +12021,7 @@ const parsedExecutionArgument = () => {
|
|||||||
<CircularProgress />
|
<CircularProgress />
|
||||||
) : (
|
) : (
|
||||||
executionData.results.map((data, index) => {
|
executionData.results.map((data, index) => {
|
||||||
if (
|
if (executionData.results.length !== 1 && !showSkippedActions && (data.status === "SKIPPED") ) {
|
||||||
executionData.results.length !== 1 &&
|
|
||||||
!showSkippedActions &&
|
|
||||||
(data.status === "SKIPPED")
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12409,15 +12405,14 @@ const parsedExecutionArgument = () => {
|
|||||||
? ""
|
? ""
|
||||||
: validateJson(selectedResult.result.trim());
|
: validateJson(selectedResult.result.trim());
|
||||||
|
|
||||||
|
console.log("RESULT: ", validate.result)
|
||||||
if (validate.valid && typeof validate.result === "string") {
|
if (validate.valid && typeof validate.result === "string") {
|
||||||
console.log(validate.result)
|
|
||||||
validate.result = JSON.parse(validate.result);
|
validate.result = JSON.parse(validate.result);
|
||||||
}
|
}
|
||||||
|
|
||||||
const AppResultVariable = ({data}) => {
|
const AppResultVariable = ({data}) => {
|
||||||
const [open, setOpen] = React.useState(false)
|
const [open, setOpen] = React.useState(false)
|
||||||
const showVariable = data.value.length < 60
|
const showVariable = data.value.length < 60
|
||||||
console.log("Value: ", data.value)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{maxWidth: 600, overflowX: "hidden", }}>
|
<div style={{maxWidth: 600, overflowX: "hidden", }}>
|
||||||
|
|||||||
@@ -394,32 +394,23 @@ const chipStyle = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const validateJson = (showResult) => {
|
export const validateJson = (showResult) => {
|
||||||
//console.log("INPUT: ", showResult, typeof showResult)
|
console.log("INPUT: ", showResult, typeof showResult)
|
||||||
if (typeof showResult === 'string') {
|
if (typeof showResult === 'string') {
|
||||||
//showResult = showResult.split(" None").join(" \"None\"")
|
showResult = showResult.split(" False").join(" false")
|
||||||
showResult = showResult.split(" False").join(" false");
|
showResult = showResult.split(" True").join(" true")
|
||||||
showResult = showResult.split(" True").join(" true");
|
|
||||||
//return {
|
|
||||||
// valid: false,
|
|
||||||
// result: showResult,
|
|
||||||
//};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (typeof showResult === undefined) {
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (typeof showResult === "object" || typeof showResult === "array") {
|
if (typeof showResult === "object" || typeof showResult === "array") {
|
||||||
return {
|
return {
|
||||||
valid: true,
|
valid: true,
|
||||||
result: showResult,
|
result: showResult,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsonvalid = true;
|
var jsonvalid = true
|
||||||
try {
|
try {
|
||||||
if (!showResult.includes("{") && !showResult.includes("[")) {
|
if (!showResult.includes("{") && !showResult.includes("[")) {
|
||||||
jsonvalid = false;
|
jsonvalid = false
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showResult = showResult.split("'").join('"');
|
showResult = showResult.split("'").join('"');
|
||||||
@@ -464,6 +455,32 @@ export const validateJson = (showResult) => {
|
|||||||
jsonvalid = false
|
jsonvalid = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("RES: ", result)
|
||||||
|
// This is where we start recursing
|
||||||
|
if (jsonvalid) {
|
||||||
|
// Check fields if they can be parsed too
|
||||||
|
try {
|
||||||
|
for (const [key, value] of Object.entries(result)) {
|
||||||
|
if (typeof value === "string" && (value.startsWith("{") || value.startsWith("["))) {
|
||||||
|
console.log("INSIDE: ", key, value);
|
||||||
|
const inside_result = validateJson(value)
|
||||||
|
console.log("Inside: ", inside_result)
|
||||||
|
if (inside_result.valid) {
|
||||||
|
console.log("Replacing value since it's valid JSON!")
|
||||||
|
if (typeof inside_result.result === "string") {
|
||||||
|
const newres = JSON.parse(inside_result.result)
|
||||||
|
result[key] = newres
|
||||||
|
} else {
|
||||||
|
result[key] = inside_result.result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Failed parsing inside json subvalues: ", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//console.log("VALID: ", jsonvalid, result, typeof result)
|
//console.log("VALID: ", jsonvalid, result, typeof result)
|
||||||
return {
|
return {
|
||||||
valid: jsonvalid,
|
valid: jsonvalid,
|
||||||
|
|||||||
Reference in New Issue
Block a user