Possible bug: Eval script keeps returning no input

if (!state.hasOwnProperty('active_namespace')) { return 'get pods --all-namespaces --output=json' } else { return `get pods --namespace ${state.active_namespace} --output=json`}
if (!state.hasOwnProperty('active_namespace')) { return 'get pods --all-namespaces --output=json' } else { return `get pods --namespace ${state.active_namespace} --output=json`}
This code keeps returning no value as input to my Runnable backend script. It should return one string or the other. Instead, my script gets no input, and throws the error:
The result keys are: error
ExecutionErr: ExitCode: 4, last log lines:
parse error: Invalid numeric literal at line 1, column 8
write /dev/stdout: broken pipe
The result keys are: error
ExecutionErr: ExitCode: 4, last log lines:
parse error: Invalid numeric literal at line 1, column 8
write /dev/stdout: broken pipe
No description
No description
4 Replies
Trevor Sullivan
Trevor Sullivan11mo ago
I just had to remove the return keyword ... I could have sworn I tried that multiple times. Actually
if (state.active_namespace === undefined) { 'get pods --all-namespaces --output=json' } else { `get pods --namespace ${state.active_namespace} --output=json`}
if (state.active_namespace === undefined) { 'get pods --all-namespaces --output=json' } else { `get pods --namespace ${state.active_namespace} --output=json`}
It looks like the if keyword isn't even supported in this block, according to the browser console errors.
AppPreview.230c0eb2.js:56 Eval error in app input 'btnLoadPods' with key 'Command SyntaxError: Unexpected token 'if'
AppPreview.230c0eb2.js:56 Eval error in app input 'btnLoadPods' with key 'Command SyntaxError: Unexpected token 'if'
Sindre
Sindre11mo ago
yeah, I do not know the details, but this should work for you:
state.active_namespace === undefined ? 'get pods --all-namespaces --output=json' : `get pods --namespace ${state.active_namespace} --output=json`
state.active_namespace === undefined ? 'get pods --all-namespaces --output=json' : `get pods --namespace ${state.active_namespace} --output=json`
another option if need eval but it's a bit hard expression is to create a background runnable, and in the eval just refer to it. meaning "bg_0.result"
rubenf
rubenf11mo ago
If are not expressions in JavaScript They are control flow statements You can however build expressions that have if in them with a bit of tortuous syntax
Trevor Sullivan
Trevor Sullivan11mo ago
This is exactly what I ended up doing!