Repository navigation
fix: preserve zero and false in tool execution results #8220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ defineProps<{ | |
| <div class="mk-gray-card-sm"> | ||
| <h6 class="mb-2">{{ t('execution.details.output') }}</h6> | ||
| <div class="break-all"> | ||
| {{ data.result || '-' }} | ||
| {{ data.result == null || data.result === '' ? '-' : data.result }} | ||
| </div> | ||
| </div> | ||
| </DetailContainer> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review of the changeThe change itself is fine (and arguably a bug fix), but there are a few things worth flagging. Correctness / behaviour changes
Style / lint
// composable or util
export const displayValue = (v: unknown, fallback = '-') =>
v === null || v === undefined || v === '' ? fallback : v<div class="break-all">{{ displayValue(data.result) }}</div>@@ or a local computed @@ const resultText = computed(() => {
const v = props.data.result
return v === null || v === undefined || v === '' ? '-' : v
})
Diff hygiene
Minor
Bottom line: the fix is reasonable; just make the "missing value" policy explicit (what about |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What the change does
{{ data.result || '-' }}→{{ data.result == null || data.result === '' ? '-' : data.result }}Good: it fixes the main bug of the original line. The
||operator treated every falsy value as empty, so a legitimate result of0orfalsewas silently replaced with-. The new version correctly shows0andfalse.Potential issues
==(loose equality) will likely trip linting.data.result == nullis the idiomatic null/undefined check, buteslint:eqeqeq(often enabled in Vue/TS projects) will flag it. Safer/clearer:or keep
??for the null part.NaNis still an edge case.NaNused to fall into the'-'branch; now it renders the literal textNaN. Ifresultcan be a numeric output, decide explicitly:Type-check mismatch. If
resultis typed asstringonly (check thedefineProps<{...}>above), comparing against0/falseis dead code, and if it'sstring | number | boolean, TS/ESLint may complain about the mixed comparison in a template. Make the prop type explicit (string | number | boolean | null | undefined).Whitespace-only strings (
' ','\n') are not caught and will render as blank space — arguably fine, but if the intent is "empty →-", consider!data.result.toString().trim().Hard-coded
'-'placeholder bypasses i18n. Elsewhere you already uset(...); consider a sharedt('common.empty')/EMPTY_VALUEconstant so the dash is consistent and localized.Newlines are collapsed. With
break-allonly, multi-line command/script output renders as one blob. Ifresultis raw output,whitespace-pre-wrap break-wordsis usually better thanbreak-all(which also breaks mid-word and hurts readability).Objects/arrays would render as
[object Object](pre-existing, but worth handling:JSON.stringifyor a guarded format).Optimization suggestions
Move the logic out of the template into a
computed, which is easier to test, lint, and reuse:If this "empty → dash" pattern appears in several components, extract a small
formatResult(value)util or a global filter rather than repeating the ternary.Add a unit test covering
0,false,'',null,undefined,NaN, and a normal string — that's exactly the regression the old code had.Verdict: the change is a genuine bug fix and safe to ship; just address the
eqeqeqlint concern, decide onNaN/whitespace handling, and consider hoisting the expression into a computed property.