Catch errors in the execution of the finance-quote-helper script and

print a warning message.  Allow stock index names to be passed to
finance-quote-helper.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7623 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2002-12-05 07:19:46 +00:00
parent 9821b8879b
commit 235248a0f4
3 changed files with 53 additions and 18 deletions

View File

@ -1,3 +1,13 @@
2002-12-04 David Hampton <hampton@employees.org>
* src/quotes/finance-quote-helper.in (schemify_quote): Allow stock
index names to be passed though from gnucash to
Finance::Quote. Necessary but not sufficient to solve #88118.
* src/scm/price-quotes.scm ((gnc:fq-get-quotes)): Beef up the
error handling. Should now print a warning message if the price
quote lookup fails, instead of crashing. #100186
2002-12-04 Derek Atkins <derek@ihtfp.com> 2002-12-04 Derek Atkins <derek@ihtfp.com>
* src/register/ledger-core/split-register-p.h: * src/register/ledger-core/split-register-p.h:

View File

@ -65,7 +65,7 @@ use FileHandle;
# For example: # For example:
# $ echo '(yahoo "CSCO" "JDSU")' | ./price-quote-helper # $ echo '(yahoo "CSCO" "JDSU" "^IXIC")' | ./finance-quote-helper
# (("CSCO" (symbol . "CSCO") # (("CSCO" (symbol . "CSCO")
# (gnc:time-no-zone . "2001-03-13 19:27:00") # (gnc:time-no-zone . "2001-03-13 19:27:00")
# (last . 20.375) # (last . 20.375)
@ -73,12 +73,16 @@ use FileHandle;
# ("JDSU" (symbol . "JDSU") # ("JDSU" (symbol . "JDSU")
# (gnc:time-no-zone . "2001-03-13 19:27:00") # (gnc:time-no-zone . "2001-03-13 19:27:00")
# (last . 23.5625) # (last . 23.5625)
# (currency . "USD"))) # (currency . "USD"))
# ("^IXIC" (symbol . ^IXIC)
# (gnc:time-no-zone . 2002-12-04 17:16:00)
# (last . 1430.35)
# (currency . failed-conversion)))
# On error, the overall result may be #f, or on individual errors, the # On error, the overall result may be #f, or on individual errors, the
# list sub-item for a given symbol may be #f, like this: # list sub-item for a given symbol may be #f, like this:
# $ echo '(yahoo "CSCO" "JDSU")' | ./price-quote-helper # $ echo '(yahoo "CSCO" "JDSU")' | ./finance-quote-helper
# (#f # (#f
# ("JDSU" (symbol . "JDSU") # ("JDSU" (symbol . "JDSU")
# (gnc:time-no-zone . "2001-03-13 19:27:00") # (gnc:time-no-zone . "2001-03-13 19:27:00")
@ -278,8 +282,9 @@ sub parse_input_line {
# Make sure we have an opening ( preceeded only by whitespace. # Make sure we have an opening ( preceeded only by whitespace.
# and followed by a one word method name composed of [a-z_]+. # and followed by a one word method name composed of [a-z_]+.
# Also allow the '.' and '^' characters for stock indices.
# Kill off the whitespace if we do and grab the command. # Kill off the whitespace if we do and grab the command.
if($input !~ s/^\s*\(\s*([a-z_]+)\s+//o) { return 0; } if($input !~ s/^\s*\(\s*([\.\^a-z_]+)\s+//o) { return 0; }
my $quote_method_name = $1; my $quote_method_name = $1;

View File

@ -274,21 +274,29 @@
(define (get-quotes) (define (get-quotes)
(and quoter (and quoter
(let ((to-child (caddr quoter)) (let ((to-child (caddr quoter))
(from-child (cadr quoter))) (from-child (cadr quoter))
(results #f))
(map (map
(lambda (request) (lambda (request)
(write (list 'handling-request request)) (catch
(newline) #t
;; we need to display the first element (the method, so it (lambda ()
;; won't be quoted) and then write the rest (write (list 'handling-request request))
(display #\( to-child) (newline)
(display (car request) to-child) ;; we need to display the first element (the method, so it
(display " " to-child) ;; won't be quoted) and then write the rest
(for-each (lambda (x) (write x to-child)) (cdr request)) (display #\( to-child)
(display #\) to-child) (display (car request) to-child)
(newline to-child) (display " " to-child)
(force-output to-child) (for-each (lambda (x) (write x to-child)) (cdr request))
(read from-child)) (display #\) to-child)
(newline to-child)
(force-output to-child)
(set! results (read from-child))
;; (write (list 'results results)) (newline)
results)
(lambda (key . args)
key)))
requests)))) requests))))
(define (kill-quoter) (define (kill-quoter)
@ -597,7 +605,7 @@
(map fq-call-data->fq-calls fq-call-data)))) (map fq-call-data->fq-calls fq-call-data))))
(fq-results (and fq-calls (gnc:fq-get-quotes fq-calls))) (fq-results (and fq-calls (gnc:fq-get-quotes fq-calls)))
(commod-tz-quote-triples (commod-tz-quote-triples
(and fq-results (not (member 'missing-lib fq-results)) (and fq-results (list? (car fq-results))
(fq-results->commod-tz-quote-triples fq-call-data fq-results))) (fq-results->commod-tz-quote-triples fq-call-data fq-results)))
;; At this point commod-tz-quote-triples will either be #f or a ;; At this point commod-tz-quote-triples will either be #f or a
;; list of items. Each item will either be (commodity ;; list of items. Each item will either be (commodity
@ -627,6 +635,18 @@
Run 'update-finance-quote' as root to install them.")) Run 'update-finance-quote' as root to install them."))
(gnc:warn (_ "You are missing some needed Perl libraries. (gnc:warn (_ "You are missing some needed Perl libraries.
Run 'update-finance-quote' as root to install them.") "\n"))) Run 'update-finance-quote' as root to install them.") "\n")))
((member 'system-error fq-results)
(set! keep-going? #f)
(if (gnc:ui-is-running?)
(gnc:error-dialog
(_ "There was a system error while retrieving the price quotes."))
(gnc:warn (_ "There was a system error while retrieving the price quotes.") "\n")))
((not (list? (car fq-results)))
(set! keep-going? #f)
(if (gnc:ui-is-running?)
(gnc:error-dialog
(_ "There was an unknown error while retrieving the price quotes."))
(gnc:warn (_ "There was an unknown error while retrieving the price quotes.") "\n")))
((and (not commod-tz-quote-triples) (gnc:ui-is-running?)) ((and (not commod-tz-quote-triples) (gnc:ui-is-running?))
(gnc:error-dialog (gnc:error-dialog
(_ "Unable to get quotes or diagnose the problem.")) (_ "Unable to get quotes or diagnose the problem."))