Skip to content

Commit

Permalink
handle bad input in Args and BusyWorker components (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha authored Jun 29, 2022
1 parent 44c09da commit 718d0e0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion webui/internal/assets/assets.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion webui/internal/assets/build/work.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions webui/internal/assets/src/Args.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export default class Args extends React.Component {
render() {
let args = this.props.args;

if (args == null) {
return (
<span>null</span>
);
}

// If object has base64 encoded JSON property named 'payload', try to unwrap it.
if (args.hasOwnProperty('payload') && base64regex.test(args.payload)) {
try {
Expand Down
14 changes: 13 additions & 1 deletion webui/internal/assets/src/Processes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ class BusyWorkers extends React.Component {
worker: PropTypes.arrayOf(PropTypes.object).isRequired,
}

parseJson(input) {
if (input.length === 0) {
return null;
}

try {
return JSON.parse(input);
} catch (e) {
return {parse_error: 'not a valid JSON', value: input};
}
}

render() {
return (
<div className={styles.tableResponsive}>
Expand All @@ -28,7 +40,7 @@ class BusyWorkers extends React.Component {
return (
<tr key={worker.worker_id}>
<td>{worker.job_name}</td>
<td><Args args={JSON.parse(worker.args_json)}/></td>
<td><Args args={this.parseJson(worker.args_json)}/></td>
<td><UnixTime ts={worker.started_at}/></td>
<td><UnixTime ts={worker.checkin_at}/></td>
<td>{worker.checkin}</td>
Expand Down

0 comments on commit 718d0e0

Please sign in to comment.