From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2026E9D01D for ; Fri, 2 Jun 2023 12:04:24 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0043528326 for ; Fri, 2 Jun 2023 12:04:24 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 2 Jun 2023 12:04:23 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 478A2483E2 for ; Fri, 2 Jun 2023 12:04:23 +0200 (CEST) Message-ID: <6e31eb0a-8564-a11e-ea82-57cf345a7722@proxmox.com> Date: Fri, 2 Jun 2023 12:04:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 To: Thomas Lamprecht , Proxmox VE development discussion References: <20230419103439.2111975-1-a.lauterer@proxmox.com> <20230419103439.2111975-2-a.lauterer@proxmox.com> Content-Language: en-US From: Aaron Lauterer In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.042 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.1 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH widget-toolkit 2/2] utils: format_size: show negative size as NA X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Jun 2023 10:04:24 -0000 On 6/1/23 16:22, Thomas Lamprecht wrote: > Am 19/04/2023 um 12:34 schrieb Aaron Lauterer: >> Signed-off-by: Aaron Lauterer >> --- >> >> AFAIK we do not have negative sizes anywhere, and if, it is an >> indication that something is wrong. > > above belongs in the commit message, additionaly some background for why doing > this now (i.e., did you run into this or what made you make this change?) > good point. It happens with the first patch of the series, when we return '-1' to indicate a broken RBD image. >> >> src/Utils.js | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/src/Utils.js b/src/Utils.js >> index ef72630..8cdbe86 100644 >> --- a/src/Utils.js >> +++ b/src/Utils.js >> @@ -688,6 +688,9 @@ utilities: { >> }, >> >> format_size: function(size, useSI) { >> + if (size < 0) { >> + return gettext("N/A"); > > catching this seems OK, but I'd rather just return the value then, as "N/A" (Not > Applicable) doesn't really makes sense here and just hides a potential underlying > problem. Since 'format_size' is used in many places all over the place, what about only checking for it in the content view, where we really shouldn't expect a negative size? I think showing N/A instead of '-1 B' is more obvious. Something like this: diff --git a/www/manager6/storage/ContentView.js b/www/manager6/storage/ContentView.js index 2761b48e..c7b3d5ef 100644 --- a/www/manager6/storage/ContentView.js +++ b/www/manager6/storage/ContentView.js @@ -182,7 +182,12 @@ Ext.define('PVE.storage.ContentView', { 'size': { header: gettext('Size'), width: 100, - renderer: Proxmox.Utils.format_size, + renderer: function(size) { + if (Number(size) === -1) { + return gettext("N/A"); + } + return Proxmox.Utils.format_size(size); + }, dataIndex: 'size', }, };