Skip to content

Commit

Permalink
fix(debug): Handle different arg types in Log
Browse files Browse the repository at this point in the history
Arguments in the Log pane were rendered using a method that assumed they 
were always a string, an array, or undefined. This commit uses a more 
robust approach to stringifying them to avoid errors.

Fixes #923
  • Loading branch information
delucis committed Apr 7, 2021
1 parent 2373438 commit a7c8776
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/client/debug/log/LogEvent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
const dispatch = createEventDispatcher();
const args = action.payload.args;
const renderedArgs = typeof args === 'string' ? args : (args || []).join(',');
const renderedArgs = Array.isArray(args)
? args.map(arg => JSON.stringify(arg, null, 2)).join(',')
: JSON.stringify(args, null, 2) || '';
const playerID = action.payload.playerID;
let actionType;
switch (action.type) {
Expand Down Expand Up @@ -59,6 +61,11 @@
opacity: 1;
}
.args {
text-align: left;
white-space: pre-wrap;
}
.player0 {
border-left-color: #ff851b;
}
Expand Down Expand Up @@ -133,7 +140,7 @@
on:mouseleave={() => dispatch('mouseleave')}
on:blur={() => dispatch('mouseleave')}
>
<div>{actionType}({renderedArgs})</div>
<div class="args">{actionType}({renderedArgs})</div>
{#if metadataComponent}
<svelte:component this={metadataComponent} {metadata} />
{:else}
Expand Down

0 comments on commit a7c8776

Please sign in to comment.