From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH 1/2] import: json: Silence json-fetch output. Date: Thu, 08 Dec 2016 10:52:37 +0100 Message-ID: <87r35in3x6.fsf@gnu.org> References: <20161205050317.13222-1-bavier@member.fsf.org> <8760mw9f9d.fsf@gnu.org> <20161207235758.455406ed@centurylink.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEvNc-0001xw-6m for guix-devel@gnu.org; Thu, 08 Dec 2016 04:52:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cEvNZ-0007Aa-2u for guix-devel@gnu.org; Thu, 08 Dec 2016 04:52:44 -0500 In-Reply-To: <20161207235758.455406ed@centurylink.net> (Eric Bavier's message of "Wed, 7 Dec 2016 23:57:58 -0600") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Eric Bavier Cc: guix-devel@gnu.org Eric Bavier skribis: > On Wed, 07 Dec 2016 11:59:10 +0100 > ludo@gnu.org (Ludovic Court=C3=A8s) wrote: > >> Eric Bavier skribis: >>=20 >> > * guix/import/json.scm (json-fetch): Use http-fetch instead of url-fet= ch >> > to avoid writing to stdout and a temporary file for each invocation. >> > * guix/import/gem.scm (rubygems-fetch): Do not redirect json-fetch >> > output to /dev/null. >> > * guix/import/pypi.scm (pypi-fetch): Likewise.=20=20 >>=20 >> [...] >>=20 >> > (define (json-fetch url) >> > "Return an alist representation of the JSON resource URL, or #f on = failure." >> > - (call-with-temporary-output-file >> > - (lambda (temp port) >> > - (and (url-fetch url temp) >> > - (hash-table->alist >> > - (call-with-input-file temp json->scm)))))) >> > + (and=3D> (false-if-exception (http-fetch url)) >> > + (lambda (port) >> > + (let ((result (hash-table->alist (json->scm port)))) >> > + (close-port port) >> > + result))))=20=20 >>=20 >> It=E2=80=99d be better to not catch exceptions raised by =E2=80=98http-f= etch=E2=80=99 here. >> Instead they=E2=80=99d be caught at the top level and a detailed error m= essage >> would be displayed, which is always better than silently ignoring >> issues. >>=20 >> However we=E2=80=99d need to check if there are uses where this is a pro= blem. >> For example, there might be updaters or importers that assume that #f >> means that the package doesn=E2=80=99t exist or something like that. >>=20 >> WDYT? > > The importers that use json-fetch all do something like '(and=3D> meta > ->package)', so a #f result from json-fetch is passed up to (@ (guix OK. So if we instead =E2=80=9Clet the exception through=E2=80=9D, =E2=80=98guix= import=E2=80=99 would something like =E2=80=9Cfailed to download from http://=E2=80=A6: 404 (Not = Found)=E2=80=9D, which is worse than =E2=80=9Cpackage not found in repo=E2=80=9D in this cas= e. A middle ground would be this: (guard (c ((http-get-error? c) (if (=3D 404 (http-get-error-code c)) #f ;this is =E2=80=9Cexpected=E2=80=9D, just means the pac= kage isn=E2=80=99t known (raise c)))) ;using (srfi srfi-34) here (let* ((port (json->scm port))) =E2=80=A6)) That way, 404 would still be treated as an expected error meaning =E2=80=9Cpackage does not exist in upstream repo=E2=80=9D, but more problem= atic errors (DNS lookup errors, 403, etc.) would go through. How does that sound? Thanks, Ludo=E2=80=99.