[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/2] import: json: Silence json-fetch output.
From: |
Eric Bavier |
Subject: |
Re: [PATCH 1/2] import: json: Silence json-fetch output. |
Date: |
Wed, 7 Dec 2016 23:57:58 -0600 |
On Wed, 07 Dec 2016 11:59:10 +0100
address@hidden (Ludovic Courtès) wrote:
> Eric Bavier <address@hidden> skribis:
>
> > * guix/import/json.scm (json-fetch): Use http-fetch instead of url-fetch
> > 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.
>
> [...]
>
> > (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=> (false-if-exception (http-fetch url))
> > + (lambda (port)
> > + (let ((result (hash-table->alist (json->scm port))))
> > + (close-port port)
> > + result))))
>
> It’d be better to not catch exceptions raised by ‘http-fetch’ here.
> Instead they’d be caught at the top level and a detailed error message
> would be displayed, which is always better than silently ignoring
> issues.
>
> However we’d need to check if there are uses where this is a problem.
> For example, there might be updaters or importers that assume that #f
> means that the package doesn’t exist or something like that.
>
> WDYT?
The importers that use json-fetch all do something like '(and=> meta
->package)', so a #f result from json-fetch is passed up to (@ (guix
scripts import) guix-import) and interpreted as a "import failed".
Using the false-if-exception* syntax which prints the exception message,
from guix/build/download.scm might be nicer. This is the syntax
that url-fetch uses. That syntax would need to be exported from
somewhere. WDYT?
`~Eric